From: Eduardo San Martin Morote Date: Fri, 28 Jun 2019 09:28:18 +0000 (+0200) Subject: refactor: rename matchLocation to resolveLocation X-Git-Tag: v4.0.0-alpha.0~334 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9d813303bedb63bbb9d120639aba134670b9adf;p=thirdparty%2Fvuejs%2Frouter.git refactor: rename matchLocation to resolveLocation --- diff --git a/src/components/Link.ts b/src/components/Link.ts index f24373fd..3c29d523 100644 --- a/src/components/Link.ts +++ b/src/components/Link.ts @@ -26,7 +26,7 @@ const Link: Component = { // @ts-ignore url = router.history.utils.normalizeLocation(to) // TODO: should allow a non matching url to allow dynamic routing to work - location = router.matchLocation(url, from) + location = router.resolveLocation(url, from) } else { // named or relative route // @ts-ignore @@ -35,7 +35,7 @@ const Link: Component = { ) const hash = to.hash || '' // we need to resolve first - location = router.matchLocation({ ...to, query, hash }, from) + location = router.resolveLocation({ ...to, query, hash }, from) // intentionally drop current query and hash // @ts-ignore url = router.history.utils.normalizeLocation({ @@ -44,7 +44,7 @@ const Link: Component = { ...location, }) } - const route = router.matchLocation(url, from) + const route = router.resolveLocation(url, from) // TODO: active classes // TODO: handle replace prop diff --git a/src/index.ts b/src/index.ts index d974013b..5d5afbd3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,8 @@ import { PluginFunction } from 'vue' import View from './components/View' import Link from './components/Link' +// TODO: type things + const plugin: PluginFunction = Vue => { Vue.mixin({ beforeCreate() { diff --git a/src/router.ts b/src/router.ts index daf6a37a..eb789946 100644 --- a/src/router.ts +++ b/src/router.ts @@ -50,7 +50,7 @@ export class Router { this.matcher = new RouterMatcher(options.routes) this.history.listen(async (to, from, info) => { - const matchedRoute = this.matchLocation(to, this.currentRoute) + const matchedRoute = this.resolveLocation(to, this.currentRoute) // console.log({ to, matchedRoute }) const toLocation: RouteLocationNormalized = { ...to, ...matchedRoute } @@ -109,7 +109,7 @@ export class Router { } // TODO: rename to resolveLocation? - matchLocation( + resolveLocation( location: MatcherLocation & Required, currentLocation: RouteLocationNormalized, redirectedFrom?: RouteLocationNormalized @@ -134,7 +134,7 @@ export class Router { if (typeof redirect === 'string') { // match the redirect instead - return this.matchLocation( + return this.resolveLocation( this.history.utils.normalizeLocation(redirect), currentLocation, normalizedLocation @@ -143,7 +143,7 @@ export class Router { const newLocation = redirect(normalizedLocation) if (typeof newLocation === 'string') { - return this.matchLocation( + return this.resolveLocation( this.history.utils.normalizeLocation(newLocation), currentLocation, normalizedLocation @@ -154,7 +154,7 @@ export class Router { // there was a redirect before // if (!('path' in newLocation) && !('name' in newLocation)) throw new Error('TODO: redirect canot be relative') - return this.matchLocation( + return this.resolveLocation( { ...newLocation, query: this.history.utils.normalizeQuery(newLocation.query || {}), @@ -164,7 +164,7 @@ export class Router { normalizedLocation ) } else { - return this.matchLocation( + return this.resolveLocation( { ...redirect, query: this.history.utils.normalizeQuery(redirect.query || {}), @@ -201,13 +201,13 @@ export class Router { if (typeof to === 'string' || 'path' in to) { url = this.history.utils.normalizeLocation(to) // TODO: should allow a non matching url to allow dynamic routing to work - location = this.matchLocation(url, this.currentRoute) + location = this.resolveLocation(url, this.currentRoute) } else { // named or relative route const query = to.query ? this.history.utils.normalizeQuery(to.query) : {} const hash = to.hash || '' // we need to resolve first - location = this.matchLocation({ ...to, query, hash }, this.currentRoute) + location = this.resolveLocation({ ...to, query, hash }, this.currentRoute) // intentionally drop current query and hash url = this.history.utils.normalizeLocation({ query,