Skip to content

Commit

Permalink
go to the same route will be set the same key, fix zack24q#21
Browse files Browse the repository at this point in the history
  • Loading branch information
zack24q committed Sep 25, 2017
1 parent 398f344 commit dbc2c10
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion examples/src/pages/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
<div class="index">
<p>This is the <b>index</b> page</p>
<p>random number: {{random}}</p>
<router-link to="list">go to list page</router-link>
<p>
<router-link to="/">go to index page</router-link>
</p>
<p>
<router-link to="list">go to list page</router-link>
</p>
</div>
</page>
</template>
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"url": "https://github.com/zack24q/vue-navigation/issues"
},
"homepage": "https://github.com/zack24q/vue-navigation#readme",
"dependencies": {},
"dependencies": {
"lodash": "^4.17.4"
},
"devDependencies": {
"anywhere": "^1.4.0",
"autoprefixer": "^6.7.2",
Expand Down
11 changes: 10 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isEqual from 'lodash/isEqual'
import Routes from './routes'
import Navigator from './navigator'
import NavComponent from './components/Navigation'
Expand Down Expand Up @@ -25,7 +26,15 @@ export default {
router.beforeEach((to, from, next) => {
if (!to.query[keyName]) {
const query = { ...to.query }
query[keyName] = genKey()
// go to the same route will have same key
if (to.path === from.path && isEqual(
{ ...to.query, [keyName]: null },
{ ...from.query, [keyName]: null },
) && from.query[keyName]) {
query[keyName] = from.query[keyName]
} else {
query[keyName] = genKey()
}
next({ path: to.path, query, replace: replaceFlag || !from.query[keyName] })
} else {
next()
Expand Down

0 comments on commit dbc2c10

Please sign in to comment.