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 { HashHistory } from './history/hash'
|
||||||
import { HTML5History } from './history/html5'
|
import { HTML5History } from './history/html5'
|
||||||
import { supportsPushState } from '../util/env'
|
import { supportsPushState } from '../util/env'
|
||||||
|
import * as dom from '../util/dom'
|
||||||
|
|
||||||
export function routerMixin (proto) {
|
export function routerMixin (proto) {
|
||||||
proto.route = {}
|
proto.route = {}
|
||||||
@ -8,6 +9,12 @@ export function routerMixin (proto) {
|
|||||||
|
|
||||||
let lastRoute = {}
|
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) {
|
export function initRouter (vm) {
|
||||||
const config = vm.config
|
const config = vm.config
|
||||||
const mode = config.routerMode || 'hash'
|
const mode = config.routerMode || 'hash'
|
||||||
@ -20,13 +27,11 @@ export function initRouter (vm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vm.router = router
|
vm.router = router
|
||||||
|
updateRender(vm)
|
||||||
router.normalize()
|
lastRoute = vm.route
|
||||||
lastRoute = vm.route = router.parse()
|
|
||||||
|
|
||||||
router.onchange(_ => {
|
router.onchange(_ => {
|
||||||
router.normalize()
|
updateRender(vm)
|
||||||
vm.route = router.parse()
|
|
||||||
vm._updateRender()
|
vm._updateRender()
|
||||||
|
|
||||||
if (lastRoute.path === vm.route.path) {
|
if (lastRoute.path === vm.route.path) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user