在src/router/index.js中将 export const routes改为publicRoutes就无法显示
来源:3-7 构建登录页面 UI 结构
StaryJie
2023-04-14
import {
createRouter,
createWebHashHistory
} from 'vue-router'
/**
* 公开路由表
*/
export const routes = [{
path: '/login',
name: 'login',
component: () => import('@/views/login/index')
}]
/**
* 这么配置页面就无法显示
*/
// export const publicRoutes = [{
// path: '/login',
// name: 'login',
// component: () => import('@/views/login/index.vue')
// }]
const router = createRouter({
history: createWebHashHistory(),
routes
// publicRoutes
})
export default router这么配置的时候是能够正常显示登陆页面的,但是如果按照视频中的配置:
import {
createRouter,
createWebHashHistory
} from 'vue-router'
/**
* 公开路由表
*/
// export const routes = [{
// path: '/login',
// name: 'login',
// component: () => import('@/views/login/index')
// }]
/**
* 这么配置页面就无法显示
*/
export const publicRoutes = [{
path: '/login',
name: 'login',
component: () => import('@/views/login/index.vue')
}]
const router = createRouter({
history: createWebHashHistory(),
// routes
publicRoutes
})
export default router登陆页面一片空白,控制台报错:
p.js:146 Uncaught TypeError: Cannot read properties of undefined (reading 'forEach') at createRouterMatcher (vue-router.mjs:1486:1) at createRouter (vue-router.mjs:2942:1) at eval (index.js:24:1) at ./src/router/index.js (app.js:59:1) at __webpack_require__ (app.js:143:33) at fn (app.js:410:21) at eval (main.js:4:65) at ./src/main.js (app.js:39:1) at __webpack_require__ (app.js:143:33) at app.js:1335:109 createRouterMatcher @ vue-router.mjs:1486 createRouter @ vue-router.mjs:2942 eval @ index.js:24 ./src/router/index.js @ app.js:59 __webpack_require__ @ app.js:143 fn @ app.js:410 eval @ main.js:4 ./src/main.js @ app.js:39 __webpack_require__ @ app.js:143 (匿名) @ app.js:1335 __webpack_require__.O @ app.js:192 (匿名) @ app.js:1336 (匿名) @ app.js:1338 crack.js:1 super_copy_cracked:false content_script.js:1 Uncaught SyntaxError: Identifier 'WBSAutoFillFormTypeUndetermined' has already been declared (at content_script.js:1:1)

写回答
1回答
-
StaryJie
提问者
2023-04-14
解决了,是我自己没看清楚导致的。
export const publicRoutes = [{ path: '/login', name: 'login', component: () => import('@/views/login/index.vue') }] const router = createRouter({ history: createWebHashHistory(), // routes routes: publicRoutes })忘了要是`routes: publicRoutes`,错写成了`publicRoutes`
10
相似问题