【发布时间】:2021-05-22 05:09:26
【问题描述】:
我可以在 Vue Router 上使用一些帮助。我正在使用 Vue 3,并且一直在阅读路由器 documentation 并寻找解决方案,但我还没有找到我的问题的答案。
我对 Vue 本身还很陌生,而且我的路由器文件开始变得非常大。我尝试了几种在网上找到的不同方法来拆分我的路由器文件,但似乎都没有奏效(它们适用于以前版本的 Vue)。您是否知道我可以阅读的任何资源,或者我只是遗漏了什么?
我尝试为管理路由创建一个路由器文件,使用 router.push() 导入并推送到路由器,但是当我加载应用程序时,找不到该路由。
例子:
/router/index.js
import { createRouter, createWebHistory } from 'vue-router'
import Authentication from '@/views/Public/Authentication.vue'
import NotFound from '@/views/Public/NotFound.vue'
import NetworkError from '@/views/Public/NetworkError.vue'
import adminRoutes from '@/modules/admin/router'
const routes = [
{
path: '/',
redirect: '/admin'
},
{
path: '/auth',
name: 'Auth',
component: Authentication
},
{
path: '/:catchAll(.*)',
name: 'NotFound',
component: NotFound
},
{
path: '/404/:resource',
name: '404resource',
component: NotFound,
props: true
},
{
path: '/network-error',
name: 'NetworkError',
component: NetworkError
}
]
router.push(adminRoutes);
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
/modules/admin/router/index.js
import Admin from '@/views/Admin/Admin.vue'
import Dashboard from '@/views/Admin/Dashboard.vue'
import Settings from '@/views/Admin/Settings.vue'
export default [
{
path: '/admin',
name: 'Admin',
component: Admin,
children: [
{
path: 'Dashboard',
component: Dashboard
},
{
path: 'settings',
component: Settings
}
]
},
]
【问题讨论】:
标签: vue.js vue-router