Skip to content

Using named route persists old route params #906

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

Closed
erikgall opened this issue Nov 16, 2016 · 17 comments
Closed

Using named route persists old route params #906

erikgall opened this issue Nov 16, 2016 · 17 comments
Assignees

Comments

@erikgall
Copy link

Vue.js version

2.0.5

Vue-Router version

2.0.2

Reproduction Link

https://jsfiddle.net/erikgall/spz2j6o6/

Steps to reproduce / What is happening

The problem occurs when navigating back to a parent route (or sibling route) with no parameters from a child route that has a parameter. The bug seems to only happen when using named routes as well.

// current path: /students/classrooms/1
<router-link :to="{ name: 'students.classrooms'  }">All Classrooms</router-link>

Component/Route Hierarchy

root component --> layout component (ex. student, instructor, guest) --> page component

-> ./app.vue
---> ./students.vue
------->./students/index.vue
-------> ./students/classrooms/index.vue (path: students/classrooms)
-------> ./students/classrooms/show.vue (path: students/classrooms/:classroom)

When navigating from the show.vue component to any other component the classroom param persists and is not removed.

students/classrooms/:classroom to students/classrooms

This is an issue if you depend on using a v-if directive to render a component that should be inserted if a route param exists like in the example below.

What is Expected?

If a route contains a param it should be present in the vm.$route.params object and when navigating from that route to a new one the params object is updated to reflect the current url.

@yyx990803
Copy link
Member

Seems to be a regression introduced by #851 - @fnlctrl do you have time to look into this?

@fnlctrl
Copy link
Member

fnlctrl commented Nov 17, 2016

Yeah, I'll take a look.

@znck
Copy link
Member

znck commented Nov 17, 2016

@fnlctrl it's fixed in #910

@fnlctrl
Copy link
Member

fnlctrl commented Nov 17, 2016

👍

@erikgall
Copy link
Author

Thank you @fnlctrl @znck @yyx990803

@ghost
Copy link

ghost commented Nov 19, 2016

@fnlctrl @znck @yyx990803 thanks for fixing this however it does not seem to address the issue.
@erikgall did you check it?

i have a similar setup, entering a sub-route with a optional parameter it does not drop the param when going back to parent route.

url pattern: /store/:product?

when entering /store/blah then click <router-link :to="{name: 'store'}"... it stays on /store/blah

works perfect on 2.0.1

@fnlctrl
Copy link
Member

fnlctrl commented Nov 19, 2016

@sleewoo Are you using the latest version? If so, please provide a repro on jsfiddle, thanks!

@jeerbl
Copy link

jeerbl commented Nov 19, 2016

@sleewoo I updated to the latest version, it worked for me.

@ghost
Copy link

ghost commented Nov 19, 2016

@fnlctrl sure, updated 2.0.3 and almost deployed it to production but tests stopped me :)

@ghost
Copy link

ghost commented Nov 19, 2016

will try do a repro
@jeerbl glad it worked for you

@ghost
Copy link

ghost commented Nov 19, 2016

so here is a working version, using 2.0.1
https://jsfiddle.net/thk8c0tc/1/

and here is 2.0.3
https://jsfiddle.net/nqqLo66d/4/

clicking on /store/blah sets params to { "product": "blah" }
then clicking on /store should set params to {}
it does on 2.0.1 but on 2.0.3 params remains the same

@ghost
Copy link

ghost commented Nov 19, 2016

query works well on both versions
https://jsfiddle.net/nqqLo66d/5/
https://jsfiddle.net/thk8c0tc/3/

@ghost
Copy link

ghost commented Nov 19, 2016

most likely is a shoot in the moon but could this be related?
60a5b58

@erikgall
Copy link
Author

@sleewoo The latest release version worked for me. I don't have any optional parameters though.

@fnlctrl
Copy link
Member

fnlctrl commented Nov 19, 2016

Seems to be a bug where optional params aren't
removed. Should be an easy fix though, will do it asap.

@fnlctrl fnlctrl reopened this Nov 19, 2016
@znck
Copy link
Member

znck commented Nov 20, 2016

@fnlctrl I'll fix this one.

Route: { name: 'store', path: '/store/:product?' }
Expected: When transition from /store/:product? to /store occurs, it should have $route = {}
Solution: Don't remember optional parameters.

@saleem-git
Copy link

The issue occurs again. Using path(absolute path) works fine but named route has the same issue as described by OP.

[email protected]
[email protected]

routes: [ { path: '/addarea', name: 'addarea', component: addArea, }, ...... { path: '/distancedatatable/:type', name: 'distancedatatable', component: distanceFeeDt, }, ], });

From 'http://localhost:8080/#/distancedatatable/restaurant' and clicking on named route
<router-link to="addarea">Area</router-link>

Expected:
URL should change to
http://localhost:8080/#/addArea

Current Behavior:
http://localhost:8080/#/distancedatatable/addArea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants