Skip to content

Commit df6f2e6

Browse files
authored
Fix resource paths to use relative ./ instead of absolute / (#260)
1 parent ef0b647 commit df6f2e6

5 files changed

Lines changed: 11 additions & 9 deletions

File tree

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CROWDIN_PERSONAL_TOKEN="your_personal_token"
55
CROWDIN_PROJECT_ID="your_project_id"
66

77
# Base path for deployment (e.g., /mini-qr for deploying at domain.com/mini-qr)
8-
# Default: /
8+
# Default: ./ (relative paths, works at any sub-path without configuration)
99
BASE_PATH=/mini-qr
1010

1111
VITE_HIDE_CREDITS=false

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ dev-dist
3333

3434
# Playwright
3535
test-results/
36-
playwright-report/
36+
playwright-report/
37+
package-lock.json

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
<head>
55
<meta charset="UTF-8" />
6-
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7-
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
6+
<link rel="icon" type="image/svg+xml" href="./favicon.svg" />
7+
<link rel="apple-touch-icon" href="./apple-touch-icon.png">
88
<meta charset="UTF-8">
99
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1010
<meta http-equiv="X-UA-Compatible" content="ie=edge">

src/utils/basePath.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
export function getBasePath(): string {
99
// Vite makes BASE_PATH available at build time through import.meta.env
10-
// If BASE_PATH is not set, default to '/'
11-
return import.meta.env.BASE_PATH || '/'
10+
// If BASE_PATH is not set, default to './' for relative paths
11+
return import.meta.env.BASE_PATH || './'
1212
}
1313

1414
/**

vite.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { VitePWA } from 'vite-plugin-pwa'
77
export default defineConfig(({ mode }) => {
88
// Load environment variables
99
const env = loadEnv(mode, '.', '')
10-
// Get BASE_PATH from environment variable, default to '/'
10+
// Get BASE_PATH from environment variable, default to './' for relative paths
11+
// Using './' ensures the app works when deployed at any sub-path without configuration
1112
// Ensure base path ends with slash for proper URL construction
12-
let base = env.BASE_PATH || '/'
13-
if (base !== '/' && !base.endsWith('/')) {
13+
let base = env.BASE_PATH || './'
14+
if (!base.endsWith('/')) {
1415
base = base + '/'
1516
}
1617

0 commit comments

Comments
 (0)