Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Route Appending Query #2631

Closed
ch3njust1n opened this Issue Feb 28, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@ch3njust1n
Copy link

ch3njust1n commented Feb 28, 2019

Couldn't find anything on Stack or in the doc for router push. Leaving this here in case anyone else runs into this issue. Please update the docs.

Problem

In the code below, if I navigate to the Content vue and then search using the Search component it imported, the dynamic route will append the search to the content path instead of changing the path and bringing up the search page e.g. localhost:9090/content/search?term=foo instead of localhost:9090/search?term=foo This is caused by the dynamic route :id.

Solution

Prepend / to the path string in the object you pass to router.push() as shown below with /search.

Search:

<input 
   type="search"
   name="q"
   v-on:keydown.enter.prevent="search()"
   v-model="query">
...
search() {
   router.push({path: '/search', query: {term: this.query} })
}
...

Content:

<template>
   <Search></Search>
</template>
...

Router:

export default new Router({
	mode: 'history',
	base: process.env.BASE_URL,
	routes: [
           {
              path: '/content/:id',
              name: 'content',
              component: () => import('./views/Content.vue')
           },
           {
              path: '/search',
              name: 'search',
              component: () => import('./views/Search.vue')
           }
        ]
})
@vue-bot

This comment has been minimized.

Copy link

vue-bot commented Feb 28, 2019

Hello, your issue has been closed because it does not conform to our issue requirements. In order to ensure every issue provides the necessary information for us to investigate, we require the use of the Issue Helper when creating new issues. Thank you!

@vue-bot vue-bot closed this Feb 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.