mirror of
https://github.com/zhigang1992/docsify.git
synced 2026-06-13 08:31:15 +08:00
feat: add context attribute, fixed #191
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user