@@ -14,28 +14,38 @@ const router = createRouter({
1414 {
1515 path : '/:pathMatch(.*)*' , // 404 route not found
1616 name : 'NotFound' ,
17- component : ( ) => import ( '@/views/NotFound.vue' ) ,
17+ component : ( ) => import ( '@/views/error/ NotFound.vue' ) ,
1818 } ,
1919 ] ,
2020} ) ;
2121
22+ let progressTimeout = null ;
2223router . beforeEach ( async ( to , from ) => {
23- progress . start ( ) ;
24+ progressTimeout = setTimeout ( ( ) => progress . start ( ) , 250 ) ;
2425 const authStore = useAuthStore ( ) ;
2526
2627 // Run middleware pipeline
27- const context = { to, from, authStore } ;
28- const routeMiddleware = to . meta . middleware || [ ] ;
29- for ( const middleware of routeMiddleware ) {
30- const result = await middleware ( context ) ;
31- if ( result ) {
32- return result ; // Exit and redirect if middleware returns a route
28+ try {
29+ const context = { to, from, authStore } ;
30+ const routeMiddleware = to . meta . middleware || [ ] ;
31+ for ( const middleware of routeMiddleware ) {
32+ const result = await middleware ( context ) ;
33+ if ( result ) {
34+ return result ; // Exit and redirect if middleware returns a route
35+ }
36+ }
37+ } finally {
38+ clearTimeout ( progressTimeout ) ;
39+ if ( progress . isStarted ( ) ) {
40+ progress . done ( ) ;
3341 }
3442 }
3543} ) ;
3644
3745router . afterEach ( ( ) => {
38- progress . done ( ) ;
46+ if ( progress . isStarted ( ) ) {
47+ progress . done ( ) ;
48+ }
3949} ) ;
4050
4151export default router ;
0 commit comments