11import { History } from './base'
22import { merge , noop } from '../../util/core'
33import { on } from '../../util/dom'
4- import { parseQuery , stringifyQuery , cleanPath } from '../util'
4+ import { parseQuery , stringifyQuery , getPath , cleanPath } from '../util'
55
66export class HTML5History extends History {
77 constructor ( config ) {
@@ -10,7 +10,7 @@ export class HTML5History extends History {
1010 }
1111
1212 getCurrentPath ( ) {
13- const base = this . config . basePath
13+ const base = this . getBasePath ( )
1414 let path = window . location . pathname
1515
1616 if ( base && path . indexOf ( base ) === 0 ) {
@@ -37,15 +37,6 @@ export class HTML5History extends History {
3737 on ( 'popstate' , cb )
3838 }
3939
40- normalize ( ) {
41- let path = this . getCurrentPath ( )
42-
43- path = path . replace ( '#' , '?id=' )
44- window . history . pushState ( { key : path } , '' , path )
45-
46- return path
47- }
48-
4940 /**
5041 * Parse the url
5142 * @param {string } [path=location.href]
@@ -60,12 +51,18 @@ export class HTML5History extends History {
6051 path = path . slice ( 0 , queryIndex )
6152 }
6253
63- const baseIndex = path . indexOf ( location . origin )
54+ const base = getPath ( location . origin , this . getBasePath ( ) )
55+ const baseIndex = path . indexOf ( base )
56+
6457 if ( baseIndex > - 1 ) {
65- path = path . slice ( baseIndex + location . origin . length )
58+ path = path . slice ( baseIndex + base . length - 1 )
6659 }
6760
68- return { path, query : parseQuery ( query ) }
61+ return {
62+ path,
63+ file : this . getFile ( path ) ,
64+ query : parseQuery ( query )
65+ }
6966 }
7067
7168 toURL ( path , params , currentRoute ) {
0 commit comments