Skip to content

Commit

Permalink
feat: add context attribute, fixed #191
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Jun 23, 2017
1 parent e8117e5 commit ce0e9ac
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/core/router/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
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 = {}
}

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'
Expand All @@ -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) {
Expand Down

0 comments on commit ce0e9ac

Please sign in to comment.