Skip to content

Commit

Permalink
fix: basePath for history mode
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed May 30, 2017
1 parent 3f38810 commit fc1cd3f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const config = merge({
ga: '',
mergeNavbar: false,
formatUpdated: '',
externalLinkTarget: '_blank'
externalLinkTarget: '_blank',
routerModel: 'hash'
}, window.$docsify)

const script = document.currentScript ||
Expand Down
1 change: 0 additions & 1 deletion src/core/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export function fetchMixin (proto) {
const root = getParentPath(this.route.path)
const path = this.router.getFile(root + coverpage)

console.log(this.route.path, root, path)
if (this.route.path !== '/' || !coverpage) {
this._renderCover()
return
Expand Down
6 changes: 5 additions & 1 deletion src/core/router/history/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export class AbstractHistory extends History {
path = path.slice(0, queryIndex)
}

return { path, query: parseQuery(query) }
return {
path,
file: this.getFile(path),
query: parseQuery(query)
}
}

toURL (path, params, currentRoute) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/router/history/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export class History {
}

getFile (path) {
path = path || this.getCurrentPath()

const { config } = this
const base = this.getBasePath()

Expand Down
6 changes: 5 additions & 1 deletion src/core/router/history/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ export class HashHistory extends History {
path = path.slice(hashIndex + 1)
}

return { path, query: parseQuery(query) }
return {
path,
file: this.getFile(path),
query: parseQuery(query)
}
}

toURL (path, params, currentRoute) {
Expand Down
25 changes: 11 additions & 14 deletions src/core/router/history/html5.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { History } from './base'
import { merge, noop } from '../../util/core'
import { on } from '../../util/dom'
import { parseQuery, stringifyQuery, cleanPath } from '../util'
import { parseQuery, stringifyQuery, getPath, cleanPath } from '../util'

export class HTML5History extends History {
constructor (config) {
Expand All @@ -10,7 +10,7 @@ export class HTML5History extends History {
}

getCurrentPath () {
const base = this.config.basePath
const base = this.getBasePath()
let path = window.location.pathname

if (base && path.indexOf(base) === 0) {
Expand All @@ -37,15 +37,6 @@ export class HTML5History extends History {
on('popstate', cb)
}

normalize () {
let path = this.getCurrentPath()

path = path.replace('#', '?id=')
window.history.pushState({ key: path }, '', path)

return path
}

/**
* Parse the url
* @param {string} [path=location.href]
Expand All @@ -60,12 +51,18 @@ export class HTML5History extends History {
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) {
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) {
Expand Down

0 comments on commit fc1cd3f

Please sign in to comment.