Change view / component but not URL

5

I'm working on a 404 page, it works fine, I have the following:

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

// ... alguma coisa 'not found'

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

The problem with this is that the URL changes as well, but I just want the view / component to change, and the URL stays the same.

I find it very annoying to be redirected to link , if I fool myself into anything I have to write the whole url or go through the browser autofill , anyway I do not like it.

I was wondering if there is any method / logic so you can have something like link .

In short, I want the view / component to change but not the URL, in case it falls on the route configured above (404).

Is there any way / built-in to do this with vue / vue-router, or a workaround ?

    
asked by anonymous 03.11.2017 / 19:53

2 answers

2

I've also this question in SO en, and the answer you get was this, it turns out, although I do not know if it is 'well done':

let route = this.$router.match({ name: '404' });
this.$router.history.updateRoute(route);

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

    
04.11.2017 / 11:15
0

puts a preventdefault (), so it will not do the redirect.

    
03.11.2017 / 23:30