@aurelia/router-lite
Advanced tools
Comparing version 2.1.0-dev.202304050629 to 2.1.0-dev.202304060017
@@ -5,4 +5,3 @@ import type { ICustomElementController, ICustomElementViewModel } from '@aurelia/runtime-html'; | ||
import { Params, NavigationInstruction } from './instructions'; | ||
import { IRouteConfig } from './route'; | ||
import type { RouterOptions } from './options'; | ||
import type { RouterOptions, IRouteConfig } from './options'; | ||
export interface IRouteViewModel extends ICustomElementViewModel { | ||
@@ -9,0 +8,0 @@ getRouteConfig?(parentConfig: IRouteConfig | null, routeNode: RouteNode | null): IRouteConfig | Promise<IRouteConfig>; |
@@ -1,2 +0,2 @@ | ||
export { type IViewport, FallbackFunction, } from './resources/viewport'; | ||
export { type IViewport, } from './resources/viewport'; | ||
export { RouterConfiguration, RouterRegistration, DefaultComponents, DefaultResources, ViewportCustomElement, ViewportCustomElementRegistration, LoadCustomAttribute, LoadCustomAttributeRegistration, HrefCustomAttribute, HrefCustomAttributeRegistration, IRouterConfigurationOptions, } from './configuration'; | ||
@@ -6,3 +6,3 @@ export { type IRouteViewModel, ComponentAgent, } from './component-agent'; | ||
export { ILocationManager, } from './location-manager'; | ||
export { type Routeable, type IRouteConfig, type IChildRouteConfig, RouteConfig, Route, type RouteType, route, } from './route'; | ||
export { RouteConfig, Route, type RouteType, route, } from './route'; | ||
export { IRouteContext, RouteContext, type INavigationModel, type INavigationRoute, } from './route-context'; | ||
@@ -12,3 +12,3 @@ export { AST, RouteExpression, CompositeSegmentExpression, ScopedSegmentExpression, SegmentGroupExpression, SegmentExpression, ComponentExpression, ActionExpression, ViewportExpression, ParameterListExpression, ParameterExpression, ExpressionKind, } from './route-expression'; | ||
export { isManagedState, toManagedState, IRouter, Router, Transition, } from './router'; | ||
export { IRouterOptions, type INavigationOptions, RouterOptions, NavigationOptions, type HistoryStrategy, } from './options'; | ||
export { IRouterOptions, type INavigationOptions, RouterOptions, NavigationOptions, type HistoryStrategy, FallbackFunction, type Routeable, type IRouteConfig, type IChildRouteConfig, } from './options'; | ||
export { AuNavId, type ManagedState, IRouterEvents, type RouterEvent, LocationChangeEvent, NavigationStartEvent, NavigationEndEvent, NavigationCancelEvent, NavigationErrorEvent, } from './router-events'; | ||
@@ -15,0 +15,0 @@ export { IStateManager, } from './state-manager'; |
@@ -1,5 +0,5 @@ | ||
import type { Params, RouteContextLike, ViewportInstructionTree } from './instructions'; | ||
import { TransitionPlan } from './route'; | ||
import type { Params, RouteContextLike, RouteableComponent, ViewportInstruction, ViewportInstructionTree } from './instructions'; | ||
import type { RouteNode } from './route-tree'; | ||
import type { Transition } from './router'; | ||
import { IRouteContext } from './route-context'; | ||
export type HistoryStrategy = 'none' | 'replace' | 'push'; | ||
@@ -97,2 +97,81 @@ export type ValueOrFunc<T extends string> = T | ((instructions: ViewportInstructionTree) => T); | ||
} | ||
export type FallbackFunction = (viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext) => Routeable | null; | ||
/** | ||
* Either a `RouteableComponent` or a name/config that can be resolved to a one: | ||
* - `string`: a string representing the component name. Must be resolveable via DI from the context of the component relative to which the navigation occurs (specified in the `dependencies` array, `<import>`ed in the view, declared as an inline template, or registered globally) | ||
* - `IChildRouteConfig`: a standalone child route config object. | ||
* - `RouteableComponent`: see `RouteableComponent`. | ||
* | ||
* NOTE: differs from `NavigationInstruction` only in having `IChildRouteConfig` instead of `IViewportIntruction` | ||
* (which in turn are quite similar, but do have a few minor but important differences that make them non-interchangeable) | ||
* as well as `IRedirectRouteConfig` | ||
*/ | ||
export type Routeable = string | IChildRouteConfig | IRedirectRouteConfig | RouteableComponent; | ||
export interface IRouteConfig { | ||
/** | ||
* The id for this route, which can be used in the view for generating hrefs. | ||
*/ | ||
readonly id?: string | null; | ||
/** | ||
* The path to match against the url. | ||
* | ||
* If left blank, the path will be derived from the component's static `path` property (if it exists). | ||
*/ | ||
readonly path?: string | string[] | null; | ||
/** | ||
* The title to use for this route when matched. | ||
* | ||
* If left blank, this route will not contribute to the generated title. | ||
*/ | ||
readonly title?: string | ((node: RouteNode) => string | null) | null; | ||
/** | ||
* The path to which to redirect when the url matches the path in this config. | ||
*/ | ||
readonly redirectTo?: string | null; | ||
/** | ||
* Whether the `path` should be case sensitive. | ||
*/ | ||
readonly caseSensitive?: boolean; | ||
/** | ||
* How to behave when this component scheduled to be loaded again in the same viewport: | ||
* | ||
* - `replace`: completely removes the current component and creates a new one, behaving as if the component changed (default if only the parameters have changed). | ||
* - `invoke-lifecycles`: calls `canUnload`, `canLoad`, `unloading` and `loading`. | ||
* - `none`: does nothing (default if nothing has changed for the viewport). | ||
*/ | ||
readonly transitionPlan?: TransitionPlanOrFunc | null; | ||
/** | ||
* The name of the viewport this component should be loaded into. | ||
*/ | ||
readonly viewport?: string | null; | ||
/** | ||
* Any custom data that should be accessible to matched components or hooks. | ||
*/ | ||
readonly data?: Record<string, unknown>; | ||
/** | ||
* The child routes that can be navigated to from this route. See `Routeable` for more information. | ||
*/ | ||
readonly routes?: readonly Routeable[]; | ||
/** | ||
* When set, will be used to redirect unknown/unconfigured routes to this route. | ||
* Can be a route-id, route-path (route), or a custom element name; this is also the resolution/fallback order. | ||
*/ | ||
readonly fallback?: Routeable | FallbackFunction | null; | ||
/** | ||
* When set to `false`, the routes won't be included in the navigation model. | ||
* | ||
* @default true | ||
*/ | ||
readonly nav?: boolean; | ||
} | ||
export interface IChildRouteConfig extends IRouteConfig { | ||
/** | ||
* The component to load when this route is matched. | ||
*/ | ||
readonly component: Routeable; | ||
} | ||
export interface IRedirectRouteConfig extends Pick<IRouteConfig, 'caseSensitive' | 'redirectTo' | 'path'> { | ||
} | ||
export type TransitionPlan = 'none' | 'replace' | 'invoke-lifecycles'; | ||
export type TransitionPlanOrFunc = TransitionPlan | ((current: RouteNode, next: RouteNode) => TransitionPlan); | ||
//# sourceMappingURL=options.d.ts.map |
import { ILogger } from '@aurelia/kernel'; | ||
import { ICustomElementViewModel, IHydratedController, ICompiledCustomElementController } from '@aurelia/runtime-html'; | ||
import { IRouteContext } from '../route-context'; | ||
import { type ViewportInstruction } from '../instructions'; | ||
import { type RouteNode } from '../route-tree'; | ||
export type FallbackFunction = (viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext) => string | null; | ||
import { FallbackFunction, Routeable } from '../options'; | ||
export interface IViewport { | ||
@@ -11,3 +9,3 @@ readonly name: string; | ||
readonly default: string; | ||
readonly fallback: string | FallbackFunction; | ||
readonly fallback: Routeable | FallbackFunction; | ||
} | ||
@@ -20,3 +18,3 @@ export declare class ViewportCustomElement implements ICustomElementViewModel, IViewport { | ||
default: string; | ||
fallback: string | FallbackFunction; | ||
fallback: Routeable | FallbackFunction; | ||
private agent; | ||
@@ -23,0 +21,0 @@ private controller; |
@@ -6,4 +6,5 @@ import { type IContainer, IModule } from '@aurelia/kernel'; | ||
import { NavigationInstruction, Params, ViewportInstruction } from './instructions'; | ||
import { IChildRouteConfig } from './options'; | ||
import { IViewport } from './resources/viewport'; | ||
import { IChildRouteConfig, RouteConfig, RouteType } from './route'; | ||
import { RouteConfig, RouteType } from './route'; | ||
import type { RouteNode } from './route-tree'; | ||
@@ -10,0 +11,0 @@ import { IRouter } from './router'; |
import { Constructable, ResourceType, IContainer } from '@aurelia/kernel'; | ||
import { RouteableComponent } from './instructions'; | ||
import type { RouteNode } from './route-tree'; | ||
import { FallbackFunction } from './resources/viewport'; | ||
import type { FallbackFunction, IChildRouteConfig, IRouteConfig, Routeable, TransitionPlan, TransitionPlanOrFunc } from './options'; | ||
export declare const noRoutes: readonly Routeable[]; | ||
/** | ||
* Either a `RouteableComponent` or a name/config that can be resolved to a one: | ||
* - `string`: a string representing the component name. Must be resolveable via DI from the context of the component relative to which the navigation occurs (specified in the `dependencies` array, `<import>`ed in the view, declared as an inline template, or registered globally) | ||
* - `IChildRouteConfig`: a standalone child route config object. | ||
* - `RouteableComponent`: see `RouteableComponent`. | ||
* | ||
* NOTE: differs from `NavigationInstruction` only in having `IChildRouteConfig` instead of `IViewportIntruction` | ||
* (which in turn are quite similar, but do have a few minor but important differences that make them non-interchangeable) | ||
* as well as `IRedirectRouteConfig` | ||
*/ | ||
export type Routeable = string | IChildRouteConfig | IRedirectRouteConfig | RouteableComponent; | ||
export interface IRouteConfig { | ||
/** | ||
* The id for this route, which can be used in the view for generating hrefs. | ||
*/ | ||
readonly id?: string | null; | ||
/** | ||
* The path to match against the url. | ||
* | ||
* If left blank, the path will be derived from the component's static `path` property (if it exists). | ||
*/ | ||
readonly path?: string | string[] | null; | ||
/** | ||
* The title to use for this route when matched. | ||
* | ||
* If left blank, this route will not contribute to the generated title. | ||
*/ | ||
readonly title?: string | ((node: RouteNode) => string | null) | null; | ||
/** | ||
* The path to which to redirect when the url matches the path in this config. | ||
*/ | ||
readonly redirectTo?: string | null; | ||
/** | ||
* Whether the `path` should be case sensitive. | ||
*/ | ||
readonly caseSensitive?: boolean; | ||
/** | ||
* How to behave when this component scheduled to be loaded again in the same viewport: | ||
* | ||
* - `replace`: completely removes the current component and creates a new one, behaving as if the component changed (default if only the parameters have changed). | ||
* - `invoke-lifecycles`: calls `canUnload`, `canLoad`, `unloading` and `loading`. | ||
* - `none`: does nothing (default if nothing has changed for the viewport). | ||
*/ | ||
readonly transitionPlan?: TransitionPlanOrFunc | null; | ||
/** | ||
* The name of the viewport this component should be loaded into. | ||
*/ | ||
readonly viewport?: string | null; | ||
/** | ||
* Any custom data that should be accessible to matched components or hooks. | ||
*/ | ||
readonly data?: Record<string, unknown>; | ||
/** | ||
* The child routes that can be navigated to from this route. See `Routeable` for more information. | ||
*/ | ||
readonly routes?: readonly Routeable[]; | ||
/** | ||
* When set, will be used to redirect unknown/unconfigured routes to this route. | ||
* Can be a route-id, route-path (route), or a custom element name; this is also the resolution/fallback order. | ||
*/ | ||
readonly fallback?: string | FallbackFunction | null; | ||
/** | ||
* When set to `false`, the routes won't be included in the navigation model. | ||
* | ||
* @default true | ||
*/ | ||
readonly nav?: boolean; | ||
} | ||
export interface IChildRouteConfig extends IRouteConfig { | ||
/** | ||
* The component to load when this route is matched. | ||
*/ | ||
readonly component: Routeable; | ||
} | ||
export interface IRedirectRouteConfig extends Pick<IRouteConfig, 'caseSensitive' | 'redirectTo' | 'path'> { | ||
} | ||
export type TransitionPlan = 'none' | 'replace' | 'invoke-lifecycles'; | ||
export type TransitionPlanOrFunc = TransitionPlan | ((current: RouteNode, next: RouteNode) => TransitionPlan); | ||
export declare class RouteConfig implements IRouteConfig, IChildRouteConfig { | ||
@@ -93,3 +14,3 @@ readonly id: string; | ||
readonly routes: readonly Routeable[]; | ||
readonly fallback: string | FallbackFunction | null; | ||
readonly fallback: Routeable | FallbackFunction | null; | ||
readonly component: Routeable; | ||
@@ -96,0 +17,0 @@ readonly nav: boolean; |
import { type PartialCustomElementDefinition } from '@aurelia/runtime-html'; | ||
import type { IChildRouteConfig, IRedirectRouteConfig } from './route'; | ||
import type { IChildRouteConfig, IRedirectRouteConfig } from './options'; | ||
import type { IViewportInstruction, Params, RouteableComponent } from './instructions'; | ||
@@ -4,0 +4,0 @@ export declare function isPartialCustomElementDefinition(value: RouteableComponent | IChildRouteConfig | null | undefined): value is PartialCustomElementDefinition; |
{ | ||
"name": "@aurelia/router-lite", | ||
"version": "2.1.0-dev.202304050629", | ||
"version": "2.1.0-dev.202304060017", | ||
"main": "dist/cjs/index.cjs", | ||
@@ -52,9 +52,9 @@ "module": "dist/esm/index.mjs", | ||
"dependencies": { | ||
"@aurelia/kernel": "2.1.0-dev.202304050629", | ||
"@aurelia/metadata": "2.1.0-dev.202304050629", | ||
"@aurelia/platform": "2.1.0-dev.202304050629", | ||
"@aurelia/platform-browser": "2.1.0-dev.202304050629", | ||
"@aurelia/route-recognizer": "2.1.0-dev.202304050629", | ||
"@aurelia/runtime": "2.1.0-dev.202304050629", | ||
"@aurelia/runtime-html": "2.1.0-dev.202304050629" | ||
"@aurelia/kernel": "2.1.0-dev.202304060017", | ||
"@aurelia/metadata": "2.1.0-dev.202304060017", | ||
"@aurelia/platform": "2.1.0-dev.202304060017", | ||
"@aurelia/platform-browser": "2.1.0-dev.202304060017", | ||
"@aurelia/route-recognizer": "2.1.0-dev.202304060017", | ||
"@aurelia/runtime": "2.1.0-dev.202304060017", | ||
"@aurelia/runtime-html": "2.1.0-dev.202304060017" | ||
}, | ||
@@ -61,0 +61,0 @@ "devDependencies": { |
@@ -13,4 +13,3 @@ import { ILogger } from '@aurelia/kernel'; | ||
import { Batch } from './util'; | ||
import { IRouteConfig } from './route'; | ||
import type { RouterOptions } from './options'; | ||
import type { RouterOptions, IRouteConfig } from './options'; | ||
@@ -17,0 +16,0 @@ export interface IRouteViewModel extends ICustomElementViewModel { |
export { | ||
type IViewport, | ||
FallbackFunction, | ||
} from './resources/viewport'; | ||
@@ -44,5 +43,2 @@ | ||
export { | ||
type Routeable, | ||
type IRouteConfig, | ||
type IChildRouteConfig, | ||
RouteConfig, | ||
@@ -95,2 +91,6 @@ Route, | ||
type HistoryStrategy, | ||
FallbackFunction, | ||
type Routeable, | ||
type IRouteConfig, | ||
type IChildRouteConfig, | ||
} from './options'; | ||
@@ -97,0 +97,0 @@ |
import { DI } from '@aurelia/kernel'; | ||
import type { Params, RouteContextLike, ViewportInstructionTree } from './instructions'; | ||
import { TransitionPlan } from './route'; | ||
import type { Params, RouteContextLike, RouteableComponent, ViewportInstruction, ViewportInstructionTree } from './instructions'; | ||
import type { RouteNode } from './route-tree'; | ||
import type { Transition } from './router'; | ||
import { IRouteContext } from './route-context'; | ||
@@ -136,1 +136,84 @@ export type HistoryStrategy = 'none' | 'replace' | 'push'; | ||
} | ||
export type FallbackFunction = (viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext) => Routeable | null; | ||
/** | ||
* Either a `RouteableComponent` or a name/config that can be resolved to a one: | ||
* - `string`: a string representing the component name. Must be resolveable via DI from the context of the component relative to which the navigation occurs (specified in the `dependencies` array, `<import>`ed in the view, declared as an inline template, or registered globally) | ||
* - `IChildRouteConfig`: a standalone child route config object. | ||
* - `RouteableComponent`: see `RouteableComponent`. | ||
* | ||
* NOTE: differs from `NavigationInstruction` only in having `IChildRouteConfig` instead of `IViewportIntruction` | ||
* (which in turn are quite similar, but do have a few minor but important differences that make them non-interchangeable) | ||
* as well as `IRedirectRouteConfig` | ||
*/ | ||
export type Routeable = string | IChildRouteConfig | IRedirectRouteConfig | RouteableComponent; | ||
export interface IRouteConfig { | ||
/** | ||
* The id for this route, which can be used in the view for generating hrefs. | ||
*/ | ||
readonly id?: string | null; | ||
/** | ||
* The path to match against the url. | ||
* | ||
* If left blank, the path will be derived from the component's static `path` property (if it exists). | ||
*/ | ||
readonly path?: string | string[] | null; | ||
/** | ||
* The title to use for this route when matched. | ||
* | ||
* If left blank, this route will not contribute to the generated title. | ||
*/ | ||
readonly title?: string | ((node: RouteNode) => string | null) | null; | ||
/** | ||
* The path to which to redirect when the url matches the path in this config. | ||
*/ | ||
readonly redirectTo?: string | null; | ||
/** | ||
* Whether the `path` should be case sensitive. | ||
*/ | ||
readonly caseSensitive?: boolean; | ||
/** | ||
* How to behave when this component scheduled to be loaded again in the same viewport: | ||
* | ||
* - `replace`: completely removes the current component and creates a new one, behaving as if the component changed (default if only the parameters have changed). | ||
* - `invoke-lifecycles`: calls `canUnload`, `canLoad`, `unloading` and `loading`. | ||
* - `none`: does nothing (default if nothing has changed for the viewport). | ||
*/ | ||
readonly transitionPlan?: TransitionPlanOrFunc | null; | ||
/** | ||
* The name of the viewport this component should be loaded into. | ||
*/ | ||
readonly viewport?: string | null; | ||
/** | ||
* Any custom data that should be accessible to matched components or hooks. | ||
*/ | ||
readonly data?: Record<string, unknown>; | ||
/** | ||
* The child routes that can be navigated to from this route. See `Routeable` for more information. | ||
*/ | ||
readonly routes?: readonly Routeable[]; | ||
/** | ||
* When set, will be used to redirect unknown/unconfigured routes to this route. | ||
* Can be a route-id, route-path (route), or a custom element name; this is also the resolution/fallback order. | ||
*/ | ||
readonly fallback?: Routeable | FallbackFunction | null; | ||
/** | ||
* When set to `false`, the routes won't be included in the navigation model. | ||
* | ||
* @default true | ||
*/ | ||
readonly nav?: boolean; | ||
} | ||
export interface IChildRouteConfig extends IRouteConfig { | ||
/** | ||
* The component to load when this route is matched. | ||
*/ | ||
readonly component: Routeable; | ||
} | ||
export interface IRedirectRouteConfig extends Pick<IRouteConfig, 'caseSensitive' | 'redirectTo' | 'path'> { } | ||
export type TransitionPlan = 'none' | 'replace' | 'invoke-lifecycles'; | ||
export type TransitionPlanOrFunc = TransitionPlan | ((current: RouteNode, next: RouteNode) => TransitionPlan); |
@@ -1,2 +0,2 @@ | ||
import { ILogger } from '@aurelia/kernel'; | ||
import { Constructable, ILogger } from '@aurelia/kernel'; | ||
import { | ||
@@ -8,3 +8,4 @@ bindable, | ||
ICustomElementController, | ||
ICompiledCustomElementController | ||
ICompiledCustomElementController, | ||
CustomElement | ||
} from '@aurelia/runtime-html'; | ||
@@ -16,5 +17,4 @@ | ||
import { type RouteNode } from '../route-tree'; | ||
import { FallbackFunction, Routeable } from '../options'; | ||
export type FallbackFunction = (viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext) => string | null; | ||
export interface IViewport { | ||
@@ -24,5 +24,5 @@ readonly name: string; | ||
readonly default: string; | ||
readonly fallback: string | FallbackFunction; | ||
readonly fallback: Routeable | FallbackFunction; | ||
/** @internal */ | ||
_getFallback(viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext): string | null; | ||
_getFallback(viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext): Routeable | null; | ||
} | ||
@@ -35,3 +35,3 @@ | ||
@bindable public default: string = ''; | ||
@bindable public fallback: string | FallbackFunction = ''; | ||
@bindable public fallback: Routeable | FallbackFunction = ''; | ||
@@ -51,6 +51,7 @@ private agent: ViewportAgent = (void 0)!; | ||
/** @internal */ | ||
public _getFallback(viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext): string | null { | ||
public _getFallback(viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext): Routeable | null { | ||
const fallback = this.fallback; | ||
return typeof fallback === 'function' | ||
? fallback(viewportInstruction, routeNode, context) | ||
&& !CustomElement.isType(fallback as Constructable) | ||
? (fallback as FallbackFunction)(viewportInstruction, routeNode, context) | ||
: fallback; | ||
@@ -57,0 +58,0 @@ } |
@@ -44,5 +44,7 @@ import { | ||
NavigationOptions, | ||
IChildRouteConfig, | ||
Routeable, | ||
} from './options'; | ||
import { IViewport } from './resources/viewport'; | ||
import { IChildRouteConfig, noRoutes, resolveCustomElementDefinition, resolveRouteConfiguration, Routeable, RouteConfig, RouteType } from './route'; | ||
import { noRoutes, resolveCustomElementDefinition, resolveRouteConfiguration, RouteConfig, RouteType } from './route'; | ||
import type { RouteNode } from './route-tree'; | ||
@@ -395,3 +397,3 @@ import { | ||
public getFallbackViewportAgent(name: string): ViewportAgent | null { | ||
return this.childViewportAgents.find(x => x._isAvailable() && x.viewport.name === name && x.viewport.fallback.length > 0) ?? null; | ||
return this.childViewportAgents.find(x => x._isAvailable() && x.viewport.name === name && x.viewport.fallback !== '') ?? null; | ||
} | ||
@@ -398,0 +400,0 @@ |
@@ -440,18 +440,20 @@ import { | ||
// fallback: id -> route -> CEDefn (Route configuration) | ||
// look for a route first | ||
log.trace(`Fallback is set to '${fallback}'. Looking for a recognized route.`); | ||
const rd = (ctx.childRoutes as RouteConfig[]).find(x => x.id === fallback); | ||
if (rd !== void 0) return appendNode(log, node, createFallbackNode(log, rd, node, vi as ViewportInstruction<ITypedNavigationInstruction_string>)); | ||
if (typeof fallback === 'string') { | ||
// fallback: id -> route -> CEDefn (Route configuration) | ||
// look for a route first | ||
log.trace(`Fallback is set to '${fallback}'. Looking for a recognized route.`); | ||
const rd = (ctx.childRoutes as RouteConfig[]).find(x => x.id === fallback); | ||
if (rd !== void 0) return appendNode(log, node, createFallbackNode(log, rd, node, vi as ViewportInstruction<ITypedNavigationInstruction_string>)); | ||
log.trace(`No route configuration for the fallback '${fallback}' is found; trying to recognize the route.`); | ||
const rr = ctx.recognize(fallback, true); | ||
if (rr !== null && rr.residue !== fallback) return appendNode(log, node, createConfiguredNode(log, node, vi as ViewportInstruction<ITypedNavigationInstruction_ResolvedComponent>, rr, null)); | ||
log.trace(`No route configuration for the fallback '${fallback}' is found; trying to recognize the route.`); | ||
const rr = ctx.recognize(fallback, true); | ||
if (rr !== null && rr.residue !== fallback) return appendNode(log, node, createConfiguredNode(log, node, vi as ViewportInstruction<ITypedNavigationInstruction_ResolvedComponent>, rr, null)); | ||
} | ||
// fallback is not recognized as a configured route; treat as CE and look for a route configuration. | ||
log.trace(`The fallback '${fallback}' is not recognized as a route; treating as custom element name.`); | ||
return appendNode(log, node, createFallbackNode(log, | ||
resolveRouteConfiguration(fallback, false, ctx.config, null, ctx) as RouteConfig, // TODO: fix the typing by adding overloads. | ||
node, | ||
vi as ViewportInstruction<ITypedNavigationInstruction_string>)); | ||
return onResolve( | ||
resolveRouteConfiguration(fallback, false, ctx.config, null, ctx), | ||
rc => appendNode(log, node, createFallbackNode(log, rc, node, vi as ViewportInstruction<ITypedNavigationInstruction_string>)) | ||
); | ||
} | ||
@@ -458,0 +460,0 @@ |
@@ -5,5 +5,4 @@ import { Metadata } from '@aurelia/metadata'; | ||
import { validateRouteConfig, expectType, shallowEquals, isPartialRedirectRouteConfig, isPartialChildRouteConfig } from './validation'; | ||
import { defaultViewportName, ITypedNavigationInstruction_Component, NavigationInstructionType, RouteableComponent, TypedNavigationInstruction, ViewportInstruction } from './instructions'; | ||
import { defaultViewportName, ITypedNavigationInstruction_Component, NavigationInstructionType, TypedNavigationInstruction, ViewportInstruction } from './instructions'; | ||
import type { RouteNode } from './route-tree'; | ||
import { FallbackFunction } from './resources/viewport'; | ||
import type { IRouteContext } from './route-context'; | ||
@@ -13,85 +12,6 @@ import { CustomElement, CustomElementDefinition } from '@aurelia/runtime-html'; | ||
import { ensureArrayOfStrings, ensureString } from './util'; | ||
import type { FallbackFunction, IChildRouteConfig, IRedirectRouteConfig, IRouteConfig, Routeable, TransitionPlan, TransitionPlanOrFunc } from './options'; | ||
export const noRoutes = emptyArray as RouteConfig['routes']; | ||
/** | ||
* Either a `RouteableComponent` or a name/config that can be resolved to a one: | ||
* - `string`: a string representing the component name. Must be resolveable via DI from the context of the component relative to which the navigation occurs (specified in the `dependencies` array, `<import>`ed in the view, declared as an inline template, or registered globally) | ||
* - `IChildRouteConfig`: a standalone child route config object. | ||
* - `RouteableComponent`: see `RouteableComponent`. | ||
* | ||
* NOTE: differs from `NavigationInstruction` only in having `IChildRouteConfig` instead of `IViewportIntruction` | ||
* (which in turn are quite similar, but do have a few minor but important differences that make them non-interchangeable) | ||
* as well as `IRedirectRouteConfig` | ||
*/ | ||
export type Routeable = string | IChildRouteConfig | IRedirectRouteConfig | RouteableComponent; | ||
export interface IRouteConfig { | ||
/** | ||
* The id for this route, which can be used in the view for generating hrefs. | ||
*/ | ||
readonly id?: string | null; | ||
/** | ||
* The path to match against the url. | ||
* | ||
* If left blank, the path will be derived from the component's static `path` property (if it exists). | ||
*/ | ||
readonly path?: string | string[] | null; | ||
/** | ||
* The title to use for this route when matched. | ||
* | ||
* If left blank, this route will not contribute to the generated title. | ||
*/ | ||
readonly title?: string | ((node: RouteNode) => string | null) | null; | ||
/** | ||
* The path to which to redirect when the url matches the path in this config. | ||
*/ | ||
readonly redirectTo?: string | null; | ||
/** | ||
* Whether the `path` should be case sensitive. | ||
*/ | ||
readonly caseSensitive?: boolean; | ||
/** | ||
* How to behave when this component scheduled to be loaded again in the same viewport: | ||
* | ||
* - `replace`: completely removes the current component and creates a new one, behaving as if the component changed (default if only the parameters have changed). | ||
* - `invoke-lifecycles`: calls `canUnload`, `canLoad`, `unloading` and `loading`. | ||
* - `none`: does nothing (default if nothing has changed for the viewport). | ||
*/ | ||
readonly transitionPlan?: TransitionPlanOrFunc | null; | ||
/** | ||
* The name of the viewport this component should be loaded into. | ||
*/ | ||
readonly viewport?: string | null; | ||
/** | ||
* Any custom data that should be accessible to matched components or hooks. | ||
*/ | ||
readonly data?: Record<string, unknown>; | ||
/** | ||
* The child routes that can be navigated to from this route. See `Routeable` for more information. | ||
*/ | ||
readonly routes?: readonly Routeable[]; | ||
/** | ||
* When set, will be used to redirect unknown/unconfigured routes to this route. | ||
* Can be a route-id, route-path (route), or a custom element name; this is also the resolution/fallback order. | ||
*/ | ||
readonly fallback?: string | FallbackFunction | null; | ||
/** | ||
* When set to `false`, the routes won't be included in the navigation model. | ||
* | ||
* @default true | ||
*/ | ||
readonly nav?: boolean; | ||
} | ||
export interface IChildRouteConfig extends IRouteConfig { | ||
/** | ||
* The component to load when this route is matched. | ||
*/ | ||
readonly component: Routeable; | ||
} | ||
export interface IRedirectRouteConfig extends Pick<IRouteConfig, 'caseSensitive' | 'redirectTo' | 'path'> { } | ||
export type TransitionPlan = 'none' | 'replace' | 'invoke-lifecycles'; | ||
export type TransitionPlanOrFunc = TransitionPlan | ((current: RouteNode, next: RouteNode) => TransitionPlan); | ||
function defaultReentryBehavior(current: RouteNode, next: RouteNode): TransitionPlan { | ||
@@ -126,3 +46,3 @@ if (!shallowEquals(current.params, next.params)) { | ||
public readonly routes: readonly Routeable[], | ||
public readonly fallback: string | FallbackFunction | null, | ||
public readonly fallback: Routeable | FallbackFunction | null, | ||
public readonly component: Routeable, | ||
@@ -282,6 +202,7 @@ public readonly nav: boolean, | ||
/** @internal */ | ||
public _getFallback(viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext): string | null { | ||
public _getFallback(viewportInstruction: ViewportInstruction, routeNode: RouteNode, context: IRouteContext): Routeable | null { | ||
const fallback = this.fallback; | ||
return typeof fallback === 'function' | ||
? fallback(viewportInstruction, routeNode, context) | ||
&& !CustomElement.isType(fallback as Constructable) | ||
? (fallback as FallbackFunction)(viewportInstruction, routeNode, context) | ||
: fallback; | ||
@@ -296,4 +217,4 @@ } | ||
*/ | ||
const component= this.component; | ||
if(component == null) return; | ||
const component = this.component; | ||
if (component == null) return; | ||
container.register(component); | ||
@@ -300,0 +221,0 @@ } |
import type { IIndexable } from '@aurelia/kernel'; | ||
import { isCustomElementViewModel, type PartialCustomElementDefinition } from '@aurelia/runtime-html'; | ||
import type { IChildRouteConfig, IRedirectRouteConfig, Routeable } from './route'; | ||
import type { IChildRouteConfig, IRedirectRouteConfig, Routeable } from './options'; | ||
import type { IViewportInstruction, Params, RouteableComponent } from './instructions'; | ||
@@ -116,3 +116,3 @@ import { tryStringify } from './util'; | ||
case 'component': | ||
validateComponent(value, path); | ||
validateComponent(value, path, 'component'); | ||
break; | ||
@@ -125,3 +125,3 @@ case 'routes': { | ||
const childPath = `${path}[${value.indexOf(route)}]`; | ||
validateComponent(route, childPath); | ||
validateComponent(route, childPath, 'component'); | ||
} | ||
@@ -149,9 +149,3 @@ break; | ||
case 'fallback': | ||
switch(typeof value) { | ||
case 'string': | ||
case 'function': | ||
break; | ||
default: | ||
expectType('string or function', path, value); | ||
} | ||
validateComponent(value, path, 'fallback'); | ||
break; | ||
@@ -198,3 +192,3 @@ default: | ||
function validateComponent(component: Routeable | null | undefined, parentPath: string): void { | ||
function validateComponent(component: Routeable | null | undefined, parentPath: string, property: string): void { | ||
switch (typeof component) { | ||
@@ -219,3 +213,3 @@ case 'function': | ||
) { | ||
expectType(`an object with at least a 'component' property (see Routeable)`, parentPath, component); | ||
expectType(`an object with at least a '${property}' property (see Routeable)`, parentPath, component); | ||
} | ||
@@ -222,0 +216,0 @@ break; |
@@ -10,5 +10,4 @@ // No-fallthrough disabled due to large numbers of false positives | ||
import type { IRouteContext } from './route-context'; | ||
import type { NavigationOptions } from './options'; | ||
import type { NavigationOptions, TransitionPlan } from './options'; | ||
import type { Transition } from './router'; | ||
import type { TransitionPlan } from './route'; | ||
import { Batch, mergeDistinct } from './util'; | ||
@@ -15,0 +14,0 @@ import { ViewportInstruction, defaultViewportName } from './instructions'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1498869
27026
+ Added@aurelia/kernel@2.1.0-dev.202304060017(transitive)
+ Added@aurelia/metadata@2.1.0-dev.202304060017(transitive)
+ Added@aurelia/platform@2.1.0-dev.202304060017(transitive)
+ Added@aurelia/platform-browser@2.1.0-dev.202304060017(transitive)
+ Added@aurelia/route-recognizer@2.1.0-dev.202304060017(transitive)
+ Added@aurelia/runtime@2.1.0-dev.202304060017(transitive)
+ Added@aurelia/runtime-html@2.1.0-dev.202304060017(transitive)
- Removed@aurelia/kernel@2.1.0-dev.202304050629(transitive)
- Removed@aurelia/metadata@2.1.0-dev.202304050629(transitive)
- Removed@aurelia/platform@2.1.0-dev.202304050629(transitive)
- Removed@aurelia/platform-browser@2.1.0-dev.202304050629(transitive)
- Removed@aurelia/route-recognizer@2.1.0-dev.202304050629(transitive)
- Removed@aurelia/runtime@2.1.0-dev.202304050629(transitive)
- Removed@aurelia/runtime-html@2.1.0-dev.202304050629(transitive)