Vue-router: Sub Directory Wild Card Redirects - Feature Request

Created on 22 Feb 2016  ·  12Comments  ·  Source: vuejs/vue-router

As mentioned over on the vue forum it would be nice to have built in ability to add directory specific wildcard redirect to specific pages.

Use case:
/* => Redirects to global 404 page
/dashboard/* => Redirects missing dashboard pages to dashboard specific 404 page.
/product-category/* => Redirects missing product to category specific 404 page etc...

1.x feature intend to implement

Most helpful comment

In this example there is root-level wildcard redirect

    // not found handler
    '*': {
      component: require('./components/not-found.vue')
    },

Isn't it reasonable to implements same approach for nested routs?

E.g.

    '/': {
      component: SiteIndex,
      subRoutes: {
        '*': {
          // custom 404 page for public section
          component: Site404
        },
        ... // other routes for public section of a site
    },
    '/admin': {
        '*': {
          // custom 404 page for administrative section
          component: Admin404
        },
        *** // other routes for administrative section
      }
    },

All 12 comments

In this example there is root-level wildcard redirect

    // not found handler
    '*': {
      component: require('./components/not-found.vue')
    },

Isn't it reasonable to implements same approach for nested routs?

E.g.

    '/': {
      component: SiteIndex,
      subRoutes: {
        '*': {
          // custom 404 page for public section
          component: Site404
        },
        ... // other routes for public section of a site
    },
    '/admin': {
        '*': {
          // custom 404 page for administrative section
          component: Admin404
        },
        *** // other routes for administrative section
      }
    },

Need this pretty badly. Does anyone know of an alternative to perform a catch all?

@znck @nickspiel @smadey @enesemini @webbur @deulos Can you please use the reaction feature to add a 👍 to the issue and then delete your comments so we can cleanup a bit? Thanks!
@divmgl You can already use the '*' wildcard when defining route paths

@posva Any update on this? :) thanks

@EmmanuelBeziat This is already in 2.0, you can try it out.
As for 0.7, there is no plans of back porting as for now since the team is working on improving 2.0, and a in fact back port is unlikely to happen as the majority of the people will probably have just upgraded to 2.0 by then.

Thanks for the answer. So I won‘t use it for now, as the project is using Vue 1.0… I‘ll have it for the next. :)

Don't forget to checkout this awesome migration helper, https://github.com/vuejs/vue-migration-helper/, should help you seamlessly upgrade from 1.0 to 2.0, though a certain amount of refactor is unavoidable.

Thanks for your help!

@fnlctrl I'm unsure we want to let this go. It may not be that difficult to add the * pattern for subRoutes

@posva I didn't mean letting this go 😂 It's just that we don't have a plan for back ports yet as of now... And I honestly don't know if we're really going to have one in the future months...

@fnlctrl Oh, my bad. That's right, this is not the priority right now and may not be worth in the near future 😄

@posva well, let‘s fork v1 and add this feature by ourselves! 😛

(I'm not good enough to achieve this, but if by any chance I do it, i‘ll surely make a pull request).

Was this page helpful?
0 / 5 - 0 ratings