]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
perf: use index access for strings
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 22 Apr 2020 20:17:47 +0000 (22:17 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 22 Apr 2020 20:22:05 +0000 (22:22 +0200)
src/history/common.ts
src/history/html5.ts
src/utils/location.ts

index dd594bb50490ee43ed3eb82ca67cc9f5c84c8892..094202360368cafbc651f17043c5d0858fa1530e 100644 (file)
@@ -162,7 +162,7 @@ export function normalizeBase(base?: string): string {
   // ensure leading slash when it was removed by the regex above avoid leading
   // slash with hash because the file could be read from the disk like file://
   // and the leading slash would cause problems
-  if (base.charAt(0) !== '/' && base.charAt(0) !== '#') base = '/' + base
+  if (base[0] !== '/' && base[0] !== '#') base = '/' + base
 
   // remove the trailing slash so all other method can just do `base + fullPath`
   // to build an href
index 58878b562f630de843cd60daa800603580cb700e..6af8d757345b87b3852c3a60c00544ea7496128c 100644 (file)
@@ -39,7 +39,7 @@ function createCurrentLocation(
   if (hashPos > -1) {
     // prepend the starting slash to hash so the url starts with /#
     let pathFromHash = hash.slice(1)
-    if (pathFromHash.charAt(0) !== '/') pathFromHash = '/' + pathFromHash
+    if (pathFromHash[0] !== '/') pathFromHash = '/' + pathFromHash
     return normalizeHistoryLocation(stripBase(pathFromHash, ''))
   }
   const path = stripBase(pathname, base)
index fb82350dfef159eb52d138a9b4b4c1f0dfc1436d..84f5f98a9d8daa921da3dbacb3a7d3ea6cb87ec4 100644 (file)
@@ -95,7 +95,8 @@ export function stringifyURL(
  * @param base - base to strip off
  */
 export function stripBase(pathname: string, base: string): string {
-  if (!base || pathname.indexOf(base) !== 0) return pathname
+  // no base or base is not found at the begining
+  if (!base || pathname.indexOf(base)) return pathname
   return pathname.replace(base, '') || '/'
 }