Marian Klühspies
Marian Klühspies

Reputation: 17617

How to exclude route from history in vue-router?

I´ve implemented tabs with vue-router. When the user clicks back and forth within those tabs, but then likes to go to the previous page, he needs to press "back" multiple times to backplay each tab visit first.

Is it possible to exclude routes from the history in vue-router like:

let router = new VueRouter({
        mode: 'history',
        routes: [
             .
             .
             .
            {
                path: '/tabs/',
                name: 'tabs',
                component: TabPage
                children: [
                            {
                                path: 'tab1',
                                name: 'tab1',
                                component: Tab1Page,
                                excludeFromHistory: true
                            },
                            {
                                path: 'tab2',
                                name: 'tab2',
                                component: Tab2Page
                                excludeFromHistory: true
                            },

                ]
            }
       ]
   });

Upvotes: 2

Views: 3333

Answers (1)

Shivam Singh
Shivam Singh

Reputation: 1731

Onclick on a tab:

Instead of pushing a route to the route history, replace the existing top of the route history.

<div @click="$router.replace('/tabs/tab1')"> Tab 1 </div>

In case you are using the router-link tag

<router-link to="/tabs/tab1" replace> Tab 1 </router-link>

Upvotes: 9

Related Questions