fix: basePath for history mode
This commit is contained in:
parent
3f38810774
commit
fc1cd3f11d
6 changed files with 25 additions and 18 deletions
|
|
@ -20,7 +20,8 @@ const config = merge({
|
||||||
ga: '',
|
ga: '',
|
||||||
mergeNavbar: false,
|
mergeNavbar: false,
|
||||||
formatUpdated: '',
|
formatUpdated: '',
|
||||||
externalLinkTarget: '_blank'
|
externalLinkTarget: '_blank',
|
||||||
|
routerModel: 'hash'
|
||||||
}, window.$docsify)
|
}, window.$docsify)
|
||||||
|
|
||||||
const script = document.currentScript ||
|
const script = document.currentScript ||
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@ export function fetchMixin (proto) {
|
||||||
const root = getParentPath(this.route.path)
|
const root = getParentPath(this.route.path)
|
||||||
const path = this.router.getFile(root + coverpage)
|
const path = this.router.getFile(root + coverpage)
|
||||||
|
|
||||||
console.log(this.route.path, root, path)
|
|
||||||
if (this.route.path !== '/' || !coverpage) {
|
if (this.route.path !== '/' || !coverpage) {
|
||||||
this._renderCover()
|
this._renderCover()
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,11 @@ export class AbstractHistory extends History {
|
||||||
path = path.slice(0, queryIndex)
|
path = path.slice(0, queryIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { path, query: parseQuery(query) }
|
return {
|
||||||
|
path,
|
||||||
|
file: this.getFile(path),
|
||||||
|
query: parseQuery(query)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toURL (path, params, currentRoute) {
|
toURL (path, params, currentRoute) {
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ export class History {
|
||||||
}
|
}
|
||||||
|
|
||||||
getFile (path) {
|
getFile (path) {
|
||||||
|
path = path || this.getCurrentPath()
|
||||||
|
|
||||||
const { config } = this
|
const { config } = this
|
||||||
const base = this.getBasePath()
|
const base = this.getBasePath()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,11 @@ export class HashHistory extends History {
|
||||||
path = path.slice(hashIndex + 1)
|
path = path.slice(hashIndex + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { path, query: parseQuery(query) }
|
return {
|
||||||
|
path,
|
||||||
|
file: this.getFile(path),
|
||||||
|
query: parseQuery(query)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toURL (path, params, currentRoute) {
|
toURL (path, params, currentRoute) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { History } from './base'
|
import { History } from './base'
|
||||||
import { merge, noop } from '../../util/core'
|
import { merge, noop } from '../../util/core'
|
||||||
import { on } from '../../util/dom'
|
import { on } from '../../util/dom'
|
||||||
import { parseQuery, stringifyQuery, cleanPath } from '../util'
|
import { parseQuery, stringifyQuery, getPath, cleanPath } from '../util'
|
||||||
|
|
||||||
export class HTML5History extends History {
|
export class HTML5History extends History {
|
||||||
constructor (config) {
|
constructor (config) {
|
||||||
|
|
@ -10,7 +10,7 @@ export class HTML5History extends History {
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentPath () {
|
getCurrentPath () {
|
||||||
const base = this.config.basePath
|
const base = this.getBasePath()
|
||||||
let path = window.location.pathname
|
let path = window.location.pathname
|
||||||
|
|
||||||
if (base && path.indexOf(base) === 0) {
|
if (base && path.indexOf(base) === 0) {
|
||||||
|
|
@ -37,15 +37,6 @@ export class HTML5History extends History {
|
||||||
on('popstate', cb)
|
on('popstate', cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
normalize () {
|
|
||||||
let path = this.getCurrentPath()
|
|
||||||
|
|
||||||
path = path.replace('#', '?id=')
|
|
||||||
window.history.pushState({ key: path }, '', path)
|
|
||||||
|
|
||||||
return path
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the url
|
* Parse the url
|
||||||
* @param {string} [path=location.href]
|
* @param {string} [path=location.href]
|
||||||
|
|
@ -60,12 +51,18 @@ export class HTML5History extends History {
|
||||||
path = path.slice(0, queryIndex)
|
path = path.slice(0, queryIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseIndex = path.indexOf(location.origin)
|
const base = getPath(location.origin, this.getBasePath())
|
||||||
|
const baseIndex = path.indexOf(base)
|
||||||
|
|
||||||
if (baseIndex > -1) {
|
if (baseIndex > -1) {
|
||||||
path = path.slice(baseIndex + location.origin.length)
|
path = path.slice(baseIndex + base.length - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { path, query: parseQuery(query) }
|
return {
|
||||||
|
path,
|
||||||
|
file: this.getFile(path),
|
||||||
|
query: parseQuery(query)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toURL (path, params, currentRoute) {
|
toURL (path, params, currentRoute) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue