]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: idiomatic js
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 31 May 2021 10:00:25 +0000 (12:00 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 31 May 2021 10:00:25 +0000 (12:00 +0200)
src/history/hash.ts
src/location.ts
src/router.ts

index 6e4f5046e64aa1956e739d68e0f49740fac282f0..522b6c9e5cbb4903f85f61459d09b0e9515c69e0 100644 (file)
@@ -34,7 +34,7 @@ export function createWebHashHistory(base?: string): RouterHistory {
   // location.pathname contains an initial `/` even at the root: `https://example.com`
   base = location.host ? base || location.pathname + location.search : ''
   // allow the user to provide a `#` in the middle: `/base/#/app`
-  if (base.indexOf('#') < 0) base += '#'
+  if (!base.includes('#')) base += '#'
 
   if (__DEV__ && !base.endsWith('#/') && !base.endsWith('#')) {
     warn(
index e9e43979aafd0d8a05efd87a26ad74d3aa2cd6c0..1b64042e0159edc26726dceb724317581e312f55 100644 (file)
@@ -106,7 +106,7 @@ export function stringifyURL(
  */
 export function stripBase(pathname: string, base: string): string {
   // no base or base is not found at the beginning
-  if (!base || pathname.toLowerCase().indexOf(base.toLowerCase()))
+  if (!base || !pathname.toLowerCase().startsWith(base.toLowerCase()))
     return pathname
   return pathname.slice(base.length) || '/'
 }
index 833cb210fab8c299ca9cbd4aba9ecc06dfa5e314..c4d6ef1fe24edc0e137a99b4a329a44ca558bc71 100644 (file)
@@ -574,8 +574,7 @@ export function createRouter(options: RouterOptions): Router {
 
       if (typeof newTargetLocation === 'string') {
         newTargetLocation =
-          newTargetLocation.indexOf('?') > -1 ||
-          newTargetLocation.indexOf('#') > -1
+          newTargetLocation.includes('?') || newTargetLocation.includes('#')
             ? (newTargetLocation = locationAsObject(newTargetLocation))
             : // force empty params
               { path: newTargetLocation }
@@ -810,7 +809,7 @@ export function createRouter(options: RouterOptions): Router {
           guards = []
           for (const record of to.matched) {
             // do not trigger beforeEnter on reused views
-            if (record.beforeEnter && from.matched.indexOf(record as any) < 0) {
+            if (record.beforeEnter && !from.matched.includes(record as any)) {
               if (Array.isArray(record.beforeEnter)) {
                 for (const beforeEnter of record.beforeEnter)
                   guards.push(guardToPromiseFn(beforeEnter, to, from))