路由默认也和路由守卫
发布日期: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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:样式剧中
下一篇:vue组件

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月10日 11时41分56秒