tuandm / laravue

Admin dashboard for enterprise Laravel applications built by VueJS and Element UI https://laravue.dev
https://laravue.dev
MIT License
2.21k stars 655 forks source link

Redirect 404 for all url not match #344

Open holdon1996 opened 2 years ago

holdon1996 commented 2 years ago

How can I always redirect to 404 page if is not Logged and does not have a match of all URLs router const? I'm trying edit file router/index.js as:

{
    path: '/error/404',
    name: 'Page404',
    component: () => import('@/views/error-page/404'),
    hidden: true,
  }

{ path: '*', redirect: '/error/404', hidden: true }

And in file permission.js as:

if (whiteList.indexOf(to.matched[0] ? to.matched[0].path : '') !== -1) {
      // in the free login whitelist, go directly
      next();
    } else {
      console.log(from, to, next);
      // other pages that do not have permission to access are redirected to the login page.
      // next(`/login?redirect=${to.path}`);
      next({ path: '/error/404' });
      NProgress.done();
    }

I always receive a message error in chrome console as: Uncaught (in promise) RangeError: Maximum call stack size exceeded

If not have matched all URLs for router const, I want to redirect to the 404 page. How can I fix it?