// TODO: ensure we are leaving since we could just be changing params or not changing anything
// TODO: is it okay to resolve all matched component or should we do it in order
await Promise.all(
- from.matched.map(async ({ component }) => {
+ from.matched.map(async record => {
// TODO: cache async routes per record
- const resolvedComponent = await (typeof component === 'function'
- ? component()
- : component)
- if (resolvedComponent.beforeRouteLeave) {
- // TODO: handle the next callback
- guards.push(
- guardToPromiseFn(resolvedComponent.beforeRouteLeave, to, from)
- )
+ // TODO: handle components version. Probably repfactor in extractComponentGuards
+ if ('component' in record) {
+ const { component } = record
+ const resolvedComponent = await (typeof component === 'function'
+ ? component()
+ : component)
+ if (resolvedComponent.beforeRouteLeave) {
+ // TODO: handle the next callback
+ guards.push(
+ guardToPromiseFn(resolvedComponent.beforeRouteLeave, to, from)
+ )
+ }
}
})
)
await Promise.all(
to.matched.map(async record => {
// TODO: cache async routes per record
- const { component } = record
- const resolvedComponent = await (typeof component === 'function'
- ? component()
- : component)
- if (
- resolvedComponent.beforeRouteEnter &&
- from.matched.indexOf(record)
- ) {
- // TODO: handle the next callback
- guards.push(
- guardToPromiseFn(resolvedComponent.beforeRouteEnter, to, from)
- )
+ // TODO: handle components version. Probably repfactor in extractComponentGuards
+ if ('component' in record) {
+ const { component } = record
+ const resolvedComponent = await (typeof component === 'function'
+ ? component()
+ : component)
+ if (
+ resolvedComponent.beforeRouteEnter &&
+ from.matched.indexOf(record)
+ ) {
+ // TODO: handle the next callback
+ guards.push(
+ guardToPromiseFn(resolvedComponent.beforeRouteEnter, to, from)
+ )
+ }
}
})
)
// export type RouteComponent = TODO & RouteComponentInterface
export type RouteComponent = {
template?: string
+ render?: Function
} & RouteComponentInterface
// NOTE not sure the whole PropsTransformer thing can be usefull
// since in callbacks we don't know where we are coming from
// and I don't thin it's possible to filter out the route
// by any means
-export interface RouteRecord {
+
+interface RouteRecordCommon {
path: string // | RegExp
- component: RouteComponent | Lazy<RouteComponent>
name?: string
beforeEnter?: NavigationGuard
- // props: PT
}
+interface RouteRecordSingleView extends RouteRecordCommon {
+ component: RouteComponent | Lazy<RouteComponent>
+}
+
+interface RouteRecordMultipleViews extends RouteRecordCommon {
+ components: Record<string, RouteComponent | Lazy<RouteComponent>>
+}
+
+export type RouteRecord = RouteRecordSingleView | RouteRecordMultipleViews
+
export const START_RECORD: RouteRecord = {
path: '/',
// @ts-ignore