Skip to content

Redirect to "not-found" but Preserve Path #2453

Discussion options

You must be logged in to vote

I updated the routes to handle both "not-found" and "forbidden-access" pages in the following way:

{
  path: '/:pathMatch(.*)*', // Matches any route not defined
  name: 'not-found',
  component: () => import('@/views/NotFoundView.vue'),
},
{
  path: '/:pathMatch(.*)*',
  name: "forbidden-access",
  component: () => import("@/views/ForbiddenAccessView.vue"),
}

This change ensures that the Forbidden Access page cannot be accessed directly by typing the URL. It will only be shown through the route guard when needed.

Then, in the navigation guard, I check the authentication and role-based authorization and preserve the original URL by passing params: { pathMatch: to.path.substring(1).split('…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@posva
Comment options

posva Feb 1, 2025
Maintainer

Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants