路由默认也和路由守卫
发布日期:2021-06-29 01:52:40
浏览次数:2
分类:技术文章
本文共 809 字,大约阅读时间需要 2 分钟。
import Vue from "vue";import Router from "vue-router";Vue.use(Router);const router = new Router({ // mode: "history", // base: process.env.BASE_URL, // routes, // 默认显示首页 routes: [ // 默认显示首页 { path: "/", // 重定向页面默认加载 redirect: "/login", }, { path: "/login", component: () => import("../components/login.vue"), }, { path: "/home", component: () => import("../components/home.vue"), }, ],});//路由导航守卫router.beforeEach((to, from, next) => { //to 将要访问的路径 //from 代表从哪个路径跳转来的 // next 是一个函数,表示放行 // next() 放行 next('/login') if (to.path === "/login") return next(); //获取token const tokenStr = window.sessionStorage.getItem("token"); //没有token,强制跳转登录页 if (!tokenStr) return next("/login"); next();});export default router;
转载地址:https://blog.csdn.net/YUlangML/article/details/116537502 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
感谢大佬
[***.8.128.20]2024年04月10日 11时41分56秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Python爬虫实战:批量下载网站图片
2019-04-29
Python走心的42个代码例子
2019-04-29
Python使用openpyxl操作excel表格
2019-04-29
Python 分析电影《南方车站的聚会》
2019-04-29
使用 Scrapy 爬取去哪儿网景区信息
2019-04-29
Python抓取4A级猎头公司数据
2019-04-29
Python爬虫实战:selenium爬取电商平台商品数据
2019-04-29
Python爬虫实战:爬取股票信息
2019-04-29
简短的爬虫程序,14行Python代码轻松实现爬取网站视频
2019-04-29
pycharm的十个小技巧,让你写代码效率翻倍
2019-04-29
python数据可视化神器,我就服它
2019-04-29
Python爬虫如何实用xpath爬取豆瓣音乐
2019-04-29
python爬取网站数据四种姿势,你值得拥有
2019-04-29
python爬虫JS逆向:X咕视频密码与指纹加密分析
2019-04-29
python爬取抖音短视频详细教程(附带源码)
2019-04-29
Python爬取腾讯动漫全站漫画详细教程(附带源码)
2019-04-29
python实现电商平台秒杀商品脚本程序
2019-04-29
520快乐~用python实现520祝福弹窗
2019-04-29
Python制作属于自己的有声小说
2019-04-29
Python制作专属有声小说(调用百度语音合成接口)
2019-04-29