{ path: '/', redirect:'/home', name: 'Home', component: () => import('../views/Main.vue'), meta: { keepAlive: true ,// 标记为缓存组件 }, children:[ { path:'/home', name:'home', component:()=> import('@/views/Home.vue'), }, { path:'/matter', name: 'matter', component: () => import( '../views/Matter.vue'), }, { path:'/check', name: 'check', component: () => import( '../views/Check.vue'), meta: { preventBack: true } }, ] } 路由tab跳转的时候 是从 form‘/’to '/matter' 但是回退也是 form‘/’to '/matter' 哪里配置错了
时间: 2024-02-28 09:53:04 浏览: 26
根据您提供的代码,我发现在 Check.vue 组件中,有一个 meta 属性中的 preventBack 属性,这个属性会阻止浏览器的后退操作,导致您无法返回到 Home.vue 组件。
如果您想要实现从 Home.vue 组件跳转到 Matter.vue 组件,再从 Matter.vue 组件返回到 Home.vue 组件的效果,可以考虑将 Check.vue 组件中的 preventBack 属性移除。这样就可以正常返回到 Home.vue 组件了。
另外,如果您想要保持 Home.vue 组件的缓存状态,可以将 Main.vue 组件的 meta 标签中的 keepAlive 属性移动到 Home.vue 组件中。即将 Home.vue 组件改为以下代码:
```
<template>
<div>
<!-- Home 页面内容 -->
</div>
</template>
<script>
export default {
name: "Home",
meta: {
keepAlive: true // 标记为缓存组件
}
}
</script>
```
相关问题
使用require.context根据views文件夹下(多级文件夹)所有.vue文件路径实现路由自动匹配生成如下格式routes,routes: [{ path: '/', redirect: '/login' }, { path: '/home', name: 'home', component: () => import('@/views/Home.vue'), redirect: '/main', children: [{ path: '/main', name: 'main', component: () => import('@/views/Main/index.vue'), children: [{ path: '/xxx', name: 'xxx', component: () => import('@/views/Main/Xxx.vue'), }, { path: '/yyy', name: 'yyy', component: () => import('@/views/Main/Yyy.vue'), } ] }, { path: '/zz', name: 'zz', component: () => import('@/views/Zz/index.vue'), children: [{ path: '/mmm', name: 'mmm', component: () => import('@/views/Zz/Mmm.vue'), }] }, ] }, { path: '/login', name: 'login', component: () => import('@/views/Login.vue') } ]
你可以使用以下代码实现:
```js
const files = require.context('@/views', true, /\.vue$/)
const routes = []
files.keys().forEach(key => {
const name = key.match(/\/(\w+)\.vue$/)[1]
const path = key.replace(/^\.\//, '').replace(/\.vue$/, '').replace(/\/index$/, '')
const route = {
path: `/${path name: name,
component: files(key).default
}
if (path === 'Home') {
route.redirect = '/main'
route.children = [{
path: 'main',
name: 'main',
component: () => import('@/views/Main/index.vue'),
children: [{
path: 'xxx',
name: 'xxx',
component: () => import('@/views/Main/Xxx.vue')
}, {
path: 'yyy',
name: 'yyy',
component: () => import('@/views/Main/Yyy.vue')
}]
}, {
path: 'zz',
name: 'zz',
component: () => import('@/views/Zz/index.vue'),
children: [{
path: 'mmm',
name: 'mmm',
component: () => import('@/views/Zz/Mmm.vue')
}]
}]
}
routes.push(route)
})
routes.push({
path: '/',
redirect: '/login'
}, {
path: '/login',
name: 'login',
component: () => import('@/views/Login.vue')
})
export default routes
```
这里使用了 `require.context` 获取所有 `.vue` 文件,然后通过正则表达式获取文件名和路径,最后根据路径和组件生成路由对象,如果是 `Home` 组件,则添加子路由。最后还要添加默认路由和登录路由。
{ path: '/redirect', component: Layout, hidden: true, children: [ { path: '/redirect/:path(.*)', component: (resolve) => require(['@/views/redirect'], resolve) } ] }, //主页 { path: '/HomePage', component: () => import("@/components/file/Home-Main"), //component: (resolve) => require(['@/views/file/HomePage'], resolve), hidden: true }, { name: 'file-Converter', path: '/file-Converter/:type/', component: (resolve) => require(['@/views/file/Converter'], resolve) //component: () => import("@/views/file/Converter") } vue 配置路由不生效
你好!根据你提供的代码片段,有几个可能导致Vue路由不生效的问题:
1. 确保已经正确安装了Vue Router,并将其导入到项目中。
2. 确保在Vue实例中使用了Vue Router插件。你可以在`main.js`文件中使用以下代码进行配置:
```javascript
import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App.vue'
Vue.use(VueRouter)
const router = new VueRouter({
routes: [
// 路由配置
]
})
new Vue({
router,
render: h => h(App)
}).$mount('#app')
```
3. 确保在路由配置中使用了正确的路径。根据你的代码片段,你需要确保路径配置正确,并且在访问时使用了正确的URL。
如果你已经检查了以上几点,但问题仍然存在,请提供更多的代码和错误信息,以便我能够更好地帮助你解决问题。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)