From ce0e9acd509bae33ba02ac2d3ad8c46bbdecfcdc Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Fri, 23 Jun 2017 17:09:13 +0800 Subject: [PATCH] feat: add context attribute, fixed #191 --- src/core/router/index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/router/index.js b/src/core/router/index.js index 2c3048096..9126c81a6 100644 --- a/src/core/router/index.js +++ b/src/core/router/index.js @@ -1,6 +1,7 @@ import { HashHistory } from './history/hash' import { HTML5History } from './history/html5' import { supportsPushState } from '../util/env' +import * as dom from '../util/dom' export function routerMixin (proto) { proto.route = {} @@ -8,6 +9,12 @@ export function routerMixin (proto) { let lastRoute = {} +function updateRender(vm) { + vm.router.normalize() + vm.route = vm.router.parse() + dom.body.setAttribute('data-page', vm.route.file) +} + export function initRouter (vm) { const config = vm.config const mode = config.routerMode || 'hash' @@ -20,13 +27,11 @@ export function initRouter (vm) { } vm.router = router - - router.normalize() - lastRoute = vm.route = router.parse() + updateRender(vm) + lastRoute = vm.route router.onchange(_ => { - router.normalize() - vm.route = router.parse() + updateRender(vm) vm._updateRender() if (lastRoute.path === vm.route.path) {