-
Notifications
You must be signed in to change notification settings - Fork 26.4k
fix(router): add customRouteProcessor wip #53312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
const c = children ? {...r, children} : {...r}; | ||
if ((!c.component && !c.loadComponent) && (children || c.loadChildren) && | ||
(c.outlet && c.outlet !== PRIMARY_OUTLET)) { | ||
c.component = EmptyOutletComponent; | ||
} | ||
|
||
if (customRouteProcessor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can check if this variable is a function instead
if (typeof customRouteProcessor === 'function') {}
* Makes a copy of the config and adds any default required properties and apply the custom route | ||
* processor. | ||
*/ | ||
export function standardizeConfig(r: Route, customRouteProcessor?: (r: Route) => Route): Route { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can extract this type to use in both places:
type CustomRouteProcessorFn = (route: Route) => Route;
* processor. | ||
*/ | ||
export function standardizeConfig(r: Route, customRouteProcessor?: (r: Route) => Route): Route { | ||
const children = r.children && r.children.map(x => standardizeConfig(x, customRouteProcessor)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, we can use Optional chaining for this one.
const children = r.children && r.children.map(x => standardizeConfig(x, customRouteProcessor)); | |
const children = r.children?.map(x => standardizeConfig(x, customRouteProcessor)); |
Closing. As discussed elsewhere, this needs more design. Additionally, the linked issue would be solved by #51532 which I think would be a much more intuitive and discoverable way of doing it. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #31800
What is the new behavior?
The devs can provide a function that will be called everytime the router processes some routes, either in app startup, or when loadComponent / loadChildren resolves.