From 940141a7595b1841bdb3cb9fd115cb2ac8c8ee9c Mon Sep 17 00:00:00 2001 From: zigomir Date: Wed, 27 Jul 2016 13:21:11 -0700 Subject: [PATCH 1/2] Set current route to named route if one exists. --- .eslintrc | 3 +++ src/history/base.js | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 726bf23d7..2941d8837 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,6 +3,9 @@ "parser": "babel-eslint", "extends": "vue", "plugins": ["flow-vars"], + "env": { + "jasmine": true + }, "rules": { "flow-vars/define-flow-type": 1, "flow-vars/use-flow-type": 1 diff --git a/src/history/base.js b/src/history/base.js index 427a9cd78..6cb6d0869 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -20,7 +20,9 @@ export class History { constructor (router: VueRouter, base: ?string) { this.router = router this.base = normalizeBae(base) - this.current = router.match('/') + if (router.options && router.options.routes && router.options.routes[0]) { + this.current = router.match({ name: router.options.routes[0].name }) + } this.pending = null this.transitionTo(this.getLocation()) } From a4e4c44b87d8e6cd2d02552c5531dcb61f60ba28 Mon Sep 17 00:00:00 2001 From: zigomir Date: Wed, 27 Jul 2016 18:35:44 -0700 Subject: [PATCH 2/2] Add spec. --- test/unit/specs/history.spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/unit/specs/history.spec.js diff --git a/test/unit/specs/history.spec.js b/test/unit/specs/history.spec.js new file mode 100644 index 000000000..b6764a8bb --- /dev/null +++ b/test/unit/specs/history.spec.js @@ -0,0 +1,16 @@ +import { History } from '../../../src/history/base' +import VueRouter from '../../../src' + +describe('History', () => { + it('Sets name property on current route', () => { + const router = new VueRouter({ + mode: 'history', + routes: [ + { path: '/', name: 'home', component: {}} + ] + }) + + const history = new History(router, '/') + expect(history.current.name).toBe('home') + }) +})