keys: string[]
}
-function generateMatcher(record: RouteRecord) {
+function generateMatcher(record: RouteRecord): RouteMatcher {
const keys: pathToRegexp.Key[] = []
// TODO: if children use option end: false ?
const re = pathToRegexp(record.path, keys)
if (!matcher) throw new NoRouteMatchError(currentLocation, location)
// TODO: build up the array with children based on current location
+
+ if ('redirect' in matcher.record) throw new Error('TODO')
+
const matched = [matcher.record]
const params: RouteParams = {}
matcher = this.matchers.find(m => m.record.name === location.name)
if (!matcher) throw new NoRouteMatchError(currentLocation, location)
+ if ('redirect' in matcher.record) throw new Error('TODO')
+
// TODO: build up the array with children based on current location
const matched = [matcher.record]
}
if (!matcher) throw new NoRouteMatchError(currentLocation, location)
+ if ('redirect' in matcher.record) throw new Error('TODO')
+
// TODO: build up the array with children based on current location
const matched = [matcher.record]
| RouteQueryAndHash & LocationAsRelative & RouteLocationOptions
// exposed to the user in a very consistant way
+export type MatchedRouteRecord = Exclude<RouteRecord, RouteRecordRedirect>
+
export interface RouteLocationNormalized
extends Required<RouteQueryAndHash & LocationAsRelative & LocationAsPath> {
fullPath: string
query: HistoryQuery // the normalized version cannot have numbers
// TODO: do the same for params
name: string | void
- matched: RouteRecord[] // non-enumerable
+ matched: MatchedRouteRecord[] // non-enumerable
}
// interface PropsTransformer {
beforeEnter?: NavigationGuard
}
+type DynamicRedirect = (to: RouteLocationNormalized) => RouteLocation
+interface RouteRecordRedirect extends RouteRecordCommon {
+ redirect: RouteLocation | DynamicRedirect
+}
+
interface RouteRecordSingleView extends RouteRecordCommon {
component: RouteComponent | Lazy<RouteComponent>
}
components: Record<string, RouteComponent | Lazy<RouteComponent>>
}
-export type RouteRecord = RouteRecordSingleView | RouteRecordMultipleViews
+export type RouteRecord =
+ | RouteRecordSingleView
+ | RouteRecordMultipleViews
+ | RouteRecordRedirect
export const START_RECORD: RouteRecord = {
path: '/',
path: string
// record?
params: RouteLocationNormalized['params']
- matched: RouteRecord[]
+ matched: MatchedRouteRecord[]
}
export interface NavigationGuardCallback {
-import { RouteRecord, RouteLocationNormalized, RouteLocation } from '../types'
+import {
+ RouteLocationNormalized,
+ RouteLocation,
+ MatchedRouteRecord,
+} from '../types'
import { guardToPromiseFn } from './guardToPromiseFn'
export * from './guardToPromiseFn'
type GuardType = 'beforeRouteEnter' | 'beforeRouteUpdate' | 'beforeRouteLeave'
export async function extractComponentsGuards(
- matched: RouteRecord[],
+ matched: MatchedRouteRecord[],
guardType: GuardType,
to: RouteLocationNormalized,
from: RouteLocationNormalized