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?

1

1 Answer 1

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', ''))
    }
    ...
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.