把hashhistory改成history
//帶#
const router = createRouter({ history: createWebHashHistory(), routes })
改成不帶#的url
const router = createRouter({ history: createWebHistory(), routes })
但是報錯
Vue Router warn]: Unexpected error when starting the router: SyntaxError: Invalid arguments
結果發現No match found for location with path ,特意看了下 /dscsmgt/ 原來是vite.config.js的 base 前端的基礎路徑
解決辦法
1、把這個base註釋掉即可,
export default defineConfig({ //base: '/dscsmgt/', build: { //生產環境配置 target: 'modules', outDir: 'dscsmgt', assetsDir: 'static', minify: 'terser' // 混淆器 },
2、如果要要加前綴,可以在createWebHistory方法裏面添加參數
const router = createRouter({
history: createWebHistory('dscsmgt'),
routes
})