2

I'm working in a 404 error page functionality, I got it to work with:

const router = new VueRouter({
  routes: [
        // ...
        {
            path: '*',
            component: NotFound,
            name: '404',
            meta: {page_title: 'Vuejs&Material Demo | 404 NOT FOUND'}
        },
    ]
});

// ... not found something

this.$router.push({name: '404'});

The problem with the above is that the url changes too, but I just want the view (component) to change.

I find very annoying when a simple typo redirects to a http://example.com/404, it makes me type the url again or go from the browser autofill, either way I don't like it.

I was wondering if there is some sort of method/logic to have something like this: https://www.facebook.com/sdfsd/sfsdf/asfasfsafastgtgregre .

Bottom line, I want for the view to change but not the url.

Is there any vue/vue-router way to do this?

1 Answer 1

2

This is a little hacky, but you could update the route via the router's history object's updateRoute method:

let route = this.$router.match({ name: '404' });
this.$router.history.updateRoute(route);
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.