bdoubleu
bdoubleu

Reputation: 6127

Vue router remove params from URL

I have a route set up like below. The idea is that if a user clicks a referral link then the key is stored. In the future if the user navigates to the path /store the same component is used and the referral link will be pulled from storage.

Do I need a route for both /store and /store/:referralKey or is there a way to do this with one route?

const router = new Router({
    mode: 'history',
    routes: [
        {
            path: '/shop/:referralKey',
            name: 'shop',
            component: () => import('./views/Shop'),
            meta: {
                public: true
            }
        }
    ]
})

Upvotes: 0

Views: 2253

Answers (1)

Varit J Patel
Varit J Patel

Reputation: 3520

Add ? after the Dynamic params and vue-router will make it optional.

path: '/shop/:referralKey?'

Hope this helps!

Upvotes: 1

Related Questions