解决vue2.0路由跳转未匹配相应路由而出现空白页面的问题
来源:互联网 发布:c语言程序实例代码 编辑:程序博客网 时间:2024/06/07 12:17
在做项目的时候, 遇到前端控制路由跳转, 但是当用户手动输入错误的路由,或者是一些不符合的路由的时候, 页面就会出现一片空白, 也没有任何报错消息。
正常我们应该首先想到redirect去重定向路由, 可是测试发现http://localhost:3008/#/ 如果我们输入的地址是酱紫的, 页面并不能按照我们所想要实现的跳转到首页。
export default [ { path: '/home', component: App, title: '运维管理', children: [ { name: 'homeMain', path: '', title: '子页面', component: require('../containers/homeMain/index') } ], extra: { inMenu: true, icon: 'el-icon-chain' } }, { path: '/examine', component: App, title: '审核', children: [ { name: 'manger', path: '', title: '审核', component: require('../containers/manger/index') } ], extra: { inMenu: true, icon: 'el-icon-chain' } }, { path: '*', //*号表示匹配任意内容 component: App, title: '首页', redirect: '/home', extra: { inMenu: false } }];
那么是不是还有其他解决方法呢?
哈哈,重点代码如下:
router.beforeEach((to, from, next) => { // 此处判断条件我有看到其他人用to.matched.length ===0进行判断, 具体的还有待进一步验证,大体的思路就是这样的 if (to.fullPath === '/') { from.name ? next({ name:from.name }) : next('/home'); } else { next(); //如果匹配到正确跳转 }});
阅读全文
0 0
- 解决vue2.0路由跳转未匹配相应路由而出现空白页面的问题
- 解决vue2.0路由跳转未匹配相应用路由避免出现空白页面
- Vue2.0路由篇之路由跳转的一个小问题
- vue2.0路由的配置
- Vue2路由问题汇总
- 渲染页面--跳转路由
- 路由页面跳转
- Vue2.0路由动态路径的绑定
- Vue2 路由
- 谈页面跳转的路由技术
- angular-route注入 路由的页面跳转
- vue2.0子路由配置和跳转 vue-router: 嵌套路由
- vue2.0路由切换后页面滚动位置不变BUG
- Extjs5.0(7):根据路由跳转页面
- 【Angular】路由跳转问题;
- 解决路由循环的问题
- vue2.0 路由 学习笔记
- vue2.0——路由
- 5.10
- Netty源码分析(八)—内存池分析
- [BZOJ3282]LCT模板(单点修改,区间查询)
- HDU 4421 Bit Magic 【2-SAT】
- 数据hive常见问题
- 解决vue2.0路由跳转未匹配相应路由而出现空白页面的问题
- golang中recover和panic用法
- C3P0连接池XML版
- MIT18.06线性代数课程笔记12:使用邻接矩阵证明欧拉定理
- 【Scikit-Learn 中文文档】多类和多标签算法
- 简明 VIM 练级攻略(转)
- Java String操作
- 美国space爬虫
- 解决ssh+mysql进行插入时报dialect is not found错误