Skip to content

fix(router): add customRouteProcessor wip - #53312

Closed
eneajaho wants to merge 1 commit into
angular:mainfrom
eneajaho:feat/load-children-processor
Closed

eneajaho wants to merge 1 commit into
angular:mainfrom
eneajaho:feat/load-children-processor

Conversation

@eneajaho

@eneajaho eneajaho commented Dec 1, 2023

Copy link
Copy Markdown
Contributor

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
c.component = EmptyOutletComponent;
}

if (customRouteProcessor) {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

atscott commented Feb 1, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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