Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support subpaths deploy #31

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default defineConfig(({ mode }) => {
}
}
return {
base: './', // 设置相对路径
// 服务插件
plugins: [
json5Plugin(),
Expand Down
2 changes: 1 addition & 1 deletion vue/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_BASE_URL="/api/v1"
VITE_BASE_URL="api/v1"
9 changes: 8 additions & 1 deletion vue/src/api/http.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import axios from 'axios'

// 获取动态子路径并构建 base URL
const getBaseURL = () => {
let pathname = window.location.pathname;
pathname = pathname.endsWith('/') ? pathname.slice(0, -1) : pathname;
return `${pathname}/${import.meta.env.VITE_BASE_URL}`; // 根据实际情况调整
}

// axios对象实例
const http = axios.create({
// baseURL不设置,会自动使用当前域名
baseURL: import.meta.env.VITE_BASE_URL,
baseURL: getBaseURL(),
timeout: 60000
})

Expand Down
5 changes: 2 additions & 3 deletions vue/src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRouter, createWebHistory } from 'vue-router'
import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
{
Expand Down Expand Up @@ -71,8 +71,7 @@ const routes = [
]

const router = createRouter({
history: createWebHistory(),
base: '/',
history: createWebHashHistory(),
routes
})

Expand Down