- import {createRouter, createWebHistory} from 'vue-router'
- import routes from './routes'
- import store from '../store/index';
- import { ElMessage } from "element-plus";
-
-
- const router = createRouter({
- history: createWebHistory(),
- routes
- })
-
-
- router.beforeEach((to, from, next) => {
- if (to.path == '/login') {
- // 登录或者注册才可以往下进行
- next();
- } else {
- // 获取 token
- const token = store.state.token;
- // token 不存在
- if (token === null || token === '') {
- ElMessage.error('您还没有登录,请先登录');
- next('/login');
- } else {
- next();
- }
- }
- });
-
- export default router;
Java Map集合中get不存在的key,会抛出异常吗?
