0

Is there a way to redirect any url starting with /web/* to redirect to the same url without web?

So a url like this:

https://example.com/web/page

would redirect to:

https://example.com/page

using Vue Router, but not declaring each redirect separately?

I know I can do it like this:

const router = new VueRouter({
    routes: [
        { path: '/web/page', redirect: '/page' }
    ]
})

But is there a way to just catch everything which starts with web to the same without web?

just_user
  • 11,769
  • 19
  • 90
  • 135
  • [enter link description here](https://stackoverflow.com/questions/35664550/vue-js-redirection-to-another-page) I'm not sure, but it may come in handy. – Kerim Kuşcu Apr 11 '19 at 13:44

1 Answers1

2

I figured out a way to do it. In beforeEach the path can be checked and then corrected.

router.beforeEach((to, from, next) => {
    if (to.path.startsWith('/web')) {
        next(to.path.replace('/web', ''))
    }
    ...
})
just_user
  • 11,769
  • 19
  • 90
  • 135