Skip to content

Dynamic alias #2408

@francoisromain

Description

@francoisromain

What problem does this feature solve?

With a route defined like this:

{
    path: '/404',
    alias: '*',
    name: 'error',
    component: Error
}

When a user visit my-site.com/random-inexisting-url, the url doesn't change and it displays the error page. (this is what we want)


Now, how to to do the same with dynamic routes?

Example:

  • there is a route like my-site.com/pages/:id
  • the user visits my-site.com/pages/inexisting-id.
  • the id param is used to fetch an API. If the API returns null, there is no automatic redirection to the error page.

It is possible to manually redirect to the /error page with router.push({ name: 'error' }) or a navigation guard, but it will change the url to /error.

Is it possible to keep the original url, but still display the error page?

What does the proposed API look like?

something like router.aliasTo({name: 'error' })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions