From: Eduardo San Martin Morote Date: Mon, 31 May 2021 10:00:25 +0000 (+0200) Subject: refactor: idiomatic js X-Git-Tag: v4.0.9~33 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3416ec5f2bd636a6f854f9d1f1f0b5c312ee8f56;p=thirdparty%2Fvuejs%2Frouter.git refactor: idiomatic js --- diff --git a/src/history/hash.ts b/src/history/hash.ts index 6e4f5046..522b6c9e 100644 --- a/src/history/hash.ts +++ b/src/history/hash.ts @@ -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( diff --git a/src/location.ts b/src/location.ts index e9e43979..1b64042e 100644 --- a/src/location.ts +++ b/src/location.ts @@ -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) || '/' } diff --git a/src/router.ts b/src/router.ts index 833cb210..c4d6ef1f 100644 --- a/src/router.ts +++ b/src/router.ts @@ -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))