Skip to content

Commit

Permalink
feat(router): internal redirect render template to another route
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd authored and njfamirm committed Feb 25, 2023
1 parent 4c5f669 commit de92671
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion core/router/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export const routerOutlet = (routesConfig: RoutesConfig): unknown => {
}

const routeId = routesConfig.routeId(routeContext) ?? '';
const render = routesConfig.templates[routeId];
let render = routesConfig.templates[routeId];

while (typeof render === 'string') {
render = routesConfig.templates[render];
}

try {
if (typeof render === 'function') {
Expand Down
4 changes: 2 additions & 2 deletions core/router/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {QueryParameters} from '@alwatr/type';
* ```
*/
export type RouteContextBase = {
sectionList: Array<string | number | boolean | null>;
sectionList: Array<string | number | boolean>;
queryParamList: QueryParameters;
hash: string;
}
Expand Down Expand Up @@ -81,7 +81,7 @@ export type TemplateCallback = (routeContext: RouteContext) => unknown;
* Type of `routeConfig.templates`.
*/
export type RouterTemplates = {
[x: string]: TemplateCallback | undefined;
[x: string]: TemplateCallback | string | undefined;
home: TemplateCallback;
_404: TemplateCallback;
}
Expand Down

0 comments on commit de92671

Please sign in to comment.