constantRoutes
时间: 2023-10-01 12:11:26 浏览: 68
`constantRoutes` 是一个 Vue Router 的配置项,它是一个数组,用于存储应用中不需要进行动态权限判断的路由配置。在 Vue.js 应用中,我们可以通过在 `router/index.js` 文件中定义路由配置来使用它。
例如,我们可以创建一个名为 `constantRoutes` 的数组,其中包含了我们应用中的所有静态路由,如登录页、首页、404 页面等。这些路由不需要进行动态权限判断,因此我们可以将它们存储在 `constantRoutes` 中。
```
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
export const constantRoutes = [
{
path: '/login',
component: () => import('@/views/login/index'),
hidden: true
},
{
path: '/',
component: () => import('@/views/home/index'),
redirect: '/dashboard',
children: [
{
path: 'dashboard',
name: 'Dashboard',
component: () => import('@/views/dashboard/index'),
meta: { title: 'Dashboard', icon: 'dashboard' }
}
]
},
{
path: '/404',
component: () => import('@/views/404'),
hidden: true
},
{
path: '*',
redirect: '/404',
hidden: true
}
]
export default new Router({
mode: 'history',
routes: constantRoutes
})
```
在上面的例子中,我们定义了四个路由,其中 `constantRoutes` 数组包含了三个静态路由:登录页、首页和 404 页面。我们在 `router/index.js` 文件中创建了一个 Vue Router 实例,并将 `constantRoutes` 数组作为其 `routes` 配置项的值。这样,我们就可以在应用中使用这些静态路由了。
需要注意的是,如果我们需要进行动态权限判断的路由配置,我们应该将它们存储在另一个数组中,例如 `asyncRoutes`,并在登录成功后将其添加到 Vue Router 的路由配置中。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)