@yanhao98/vue-router-helper
All checks were successful
CI / cache-and-install (push) Successful in 59s
All checks were successful
CI / cache-and-install (push) Successful in 59s
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import NProgress from 'nprogress';
|
||||
import { createLogGuard, createProgressGuard } from '@yanhao98/vue-router-helper';
|
||||
import type { Router } from 'vue-router';
|
||||
import { createLogGuard, createStackGuard } from './log-guard';
|
||||
import { createStackGuard } from './stack-guard';
|
||||
|
||||
// Don't change the order of creation
|
||||
export function setupRouterGuard(router: Router) {
|
||||
@ -14,13 +14,3 @@ export function setupRouterGuard(router: Router) {
|
||||
console.debug('🚨 [router error]: ', error);
|
||||
});
|
||||
}
|
||||
|
||||
export function createProgressGuard(router: Router) {
|
||||
router.beforeEach(() => {
|
||||
NProgress.start();
|
||||
});
|
||||
|
||||
router.afterEach(() => {
|
||||
NProgress.done();
|
||||
});
|
||||
}
|
||||
|
@ -1,31 +1,6 @@
|
||||
import { START_LOCATION } from 'vue-router';
|
||||
import type { RouteLocationNormalized, Router } from 'vue-router';
|
||||
|
||||
export function createLogGuard(router: Router) {
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
console.debug(
|
||||
'🚗 ====================',
|
||||
`[beforeEach]`,
|
||||
`[${from === START_LOCATION ? 'START_LOCATION' : String(from.name || '')}]`,
|
||||
`-> [${String(to.name)}].`,
|
||||
'===================='
|
||||
);
|
||||
next();
|
||||
});
|
||||
|
||||
router.afterEach(async (to, from, failure) => {
|
||||
console.debug(
|
||||
'🚗 ====================',
|
||||
` [afterEach]`,
|
||||
`[${from === START_LOCATION ? 'START_LOCATION' : String(from.name || '')}]`,
|
||||
`-> [${String(to.name)}].`,
|
||||
'==================== 🚗🚗🚗',
|
||||
`failure: `,
|
||||
failure
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function createStackGuard(router: Router) {
|
||||
// const stack = router.stack = { /* list: [] as RouteLocationNormalized[], */ currentStackIndex: 0 }
|
||||
let startPosition = -1;
|
||||
@ -146,8 +121,8 @@ export function createStackGuard(router: Router) {
|
||||
curPosition = newPostion;
|
||||
console.log(
|
||||
'stack :>> ',
|
||||
stack.map((item, index) => (stackIdx === index ? `🔵 ${item.name}` : item.name)),
|
||||
stack,
|
||||
stack.map((item, index) => (stackIdx === index ? `🔵 ${item.name?.toString}` : item.name)),
|
||||
stack
|
||||
);
|
||||
console.log(`%c${'-'.repeat(80)}`, 'color: #409EFF;');
|
||||
});
|
Reference in New Issue
Block a user