// @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
)
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({
...location,
})
}
- const route = router.matchLocation(url, from)
+ const route = router.resolveLocation(url, from)
// TODO: active classes
// TODO: handle replace prop
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 }
}
// TODO: rename to resolveLocation?
- matchLocation(
+ resolveLocation(
location: MatcherLocation & Required<RouteQueryAndHash>,
currentLocation: RouteLocationNormalized,
redirectedFrom?: RouteLocationNormalized
if (typeof redirect === 'string') {
// match the redirect instead
- return this.matchLocation(
+ return this.resolveLocation(
this.history.utils.normalizeLocation(redirect),
currentLocation,
normalizedLocation
const newLocation = redirect(normalizedLocation)
if (typeof newLocation === 'string') {
- return this.matchLocation(
+ return this.resolveLocation(
this.history.utils.normalizeLocation(newLocation),
currentLocation,
normalizedLocation
// 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 || {}),
normalizedLocation
)
} else {
- return this.matchLocation(
+ return this.resolveLocation(
{
...redirect,
query: this.history.utils.normalizeQuery(redirect.query || {}),
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,