8000 fix(router): add customRouteProcessor wip by eneajaho · Pull Request #53312 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

eneajaho
Copy link
Contributor
@eneajaho eneajaho commented Dec 1, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

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.

providers: [
 {
  provide: CUSTOM_ROUTE_PROCESSOR,
  useFactory: () => {
   const routeProcessorService = inject(RouteProcessorService); // user defined service
   return (route: Route) => {
     return routeProcessorService.process(route); // this should return a Route
   }
  },
 }
]

@pullapprove pullapprove bot requested a review from AndrewKushnir December 1, 2023 14:19
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) {
Copy link
Contributor

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 {
Copy link
Contributor

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));
Copy link
Contributor

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.

Suggested change
const children = r.children && r.children.map(x => standardizeConfig(x, customRouteProcessor));
const children = r.children?.map(x => standardizeConfig(x, customRouteProcessor));

@AndrewKushnir AndrewKushnir requested a review from atscott December 1, 2023 17:37
@atscott atscott marked this pull request as draft December 1, 2023 18:11
@atscott
Copy link
Contributor
atscott commented Feb 1, 2024

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.

@atscott atscott closed this Feb 1, 2024
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0