mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
feat: add context attribute, fixed #191
This commit is contained in:
parent
e8117e515d
commit
ce0e9acd50
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user