]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(hash): fix base position for hash routing
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 19 Mar 2020 22:27:15 +0000 (23:27 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 19 Mar 2020 22:27:15 +0000 (23:27 +0100)
src/history/hash.ts
src/history/html5.ts

index 08a6cae07403f21575d98b8839dfffaef7420cca..baff034196e2dcab41f4ab45368086f4fe2e04db 100644 (file)
@@ -3,5 +3,5 @@ import createWebHistory from './html5'
 
 export default function createWebHashHistory(base: string = ''): RouterHistory {
   // Make sure this implementation is fine in terms of encoding, specially for IE11
-  return createWebHistory('/#' + base)
+  return createWebHistory(base + '/#')
 }
index 637b7523fcbf7b7daf9e25aeaa0b43af0cadfa6e..290e0438327adbe01796fc7049d2ee010d8c760a 100644 (file)
@@ -35,9 +35,12 @@ function createCurrentLocation(
 ): HistoryLocationNormalized {
   const { pathname, search, hash } = location
   // allows hash based url
-  if (base.indexOf('#') > -1) {
+  const hashPos = base.indexOf('#')
+  if (hashPos > -1) {
     // prepend the starting slash to hash so the url starts with /#
-    return normalizeHistoryLocation(stripBase('/' + hash, base))
+    let pathFromHash = hash.slice(1)
+    if (pathFromHash.charAt(0) !== '/') pathFromHash = '/' + pathFromHash
+    return normalizeHistoryLocation(stripBase(pathFromHash, ''))
   }
   const path = stripBase(pathname, base)
   return normalizeHistoryLocation(path + search + hash)
@@ -59,6 +62,8 @@ function useHistoryListeners(
   }: {
     state: StateEntry
   }) => {
+    // TODO: state can be null when using links with a `hash` in hash mode
+    // maybe we should trigger a plain navigation in that case
     cs.info('popstate fired', state)
     cs.info('currentState', historyState)