fix: 修改配置路由写法以修复热更新问题

This commit is contained in:
张传龙 2022-05-20 18:33:13 +08:00
parent df378f784b
commit f3c391c031

View File

@ -5,7 +5,7 @@ import { basicRoutes } from './routes'
const isHash = !!import.meta.env.VITE_APP_USE_HASH const isHash = !!import.meta.env.VITE_APP_USE_HASH
export const router = createRouter({ export const router = createRouter({
history: isHash ? createWebHashHistory('/') : createWebHistory('/'), history: isHash ? createWebHashHistory('/') : createWebHistory('/'),
routes: basicRoutes, routes: [],
scrollBehavior: () => ({ left: 0, top: 0 }), scrollBehavior: () => ({ left: 0, top: 0 }),
}) })
@ -20,6 +20,9 @@ export function resetRouter() {
} }
export function setupRouter(app) { export function setupRouter(app) {
basicRoutes.forEach((route) => {
!router.hasRoute(route.name) && router.addRoute(route)
})
app.use(router) app.use(router)
setupRouterGuard(router) setupRouterGuard(router)
} }