Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
fix: 🐛 router navigation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Dec 30, 2021
1 parent 3db09ba commit b550a7a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@ import { createRouterGuards } from './router-guards';

import common from '@/router/staticModules';
import shared from './staticModules/besidesLayout';
import { notFound, errorRoutes } from './staticModules/error';
import { whiteNameList } from './constant';

export const routes: Array<RouteRecordRaw> = [
{
path: '/',
name: 'Layout',
redirect: '/dashboard',
redirect: '/dashboard/welcome',
component: () => import(/* webpackChunkName: "layout" */ '@/layout/index.vue'),
meta: {
title: '首页',
},
children: [...common],
},
...shared,
notFound,
errorRoutes,
];

export const router = createRouter({
Expand All @@ -42,9 +39,11 @@ export function resetRouter() {
}

export async function setupRouter(app: App) {
app.use(router);
// 创建路由守卫
createRouterGuards(router, whiteNameList);

app.use(router);

// 路由准备就绪后挂载APP实例
await router.isReady();
}
Expand Down
3 changes: 2 additions & 1 deletion src/router/router-guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { type WhiteNameList } from './constant';
NProgress.configure({ showSpinner: false }); // NProgress Configuration

const loginRoutePath = '/login';
const defaultRoutePath = '/dashboard';
const defaultRoutePath = '/dashboard/welcome';

export function createRouterGuards(router: Router, whiteNameList: WhiteNameList) {
router.beforeEach(async (to, from, next) => {
const userStore = useUserStore();
NProgress.start(); // start progress bar
const token = Storage.get(ACCESS_TOKEN_KEY);

if (token) {
if (to.name === 'login') {
next({ path: defaultRoutePath });
Expand Down

0 comments on commit b550a7a

Please sign in to comment.