Skip to content

Commit ce0e9ac

Browse files
committed
feat: add context attribute, fixed #191
1 parent e8117e5 commit ce0e9ac

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/core/router/index.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import { HashHistory } from './history/hash'
22
import { HTML5History } from './history/html5'
33
import { supportsPushState } from '../util/env'
4+
import * as dom from '../util/dom'
45

56
export function routerMixin (proto) {
67
proto.route = {}
78
}
89

910
let lastRoute = {}
1011

12+
function updateRender(vm) {
13+
vm.router.normalize()
14+
vm.route = vm.router.parse()
15+
dom.body.setAttribute('data-page', vm.route.file)
16+
}
17+
1118
export function initRouter (vm) {
1219
const config = vm.config
1320
const mode = config.routerMode || 'hash'
@@ -20,13 +27,11 @@ export function initRouter (vm) {
2027
}
2128

2229
vm.router = router
23-
24-
router.normalize()
25-
lastRoute = vm.route = router.parse()
30+
updateRender(vm)
31+
lastRoute = vm.route
2632

2733
router.onchange(_ => {
28-
router.normalize()
29-
vm.route = router.parse()
34+
updateRender(vm)
3035
vm._updateRender()
3136

3237
if (lastRoute.path === vm.route.path) {

0 commit comments

Comments
 (0)