fix(router): support lazy loading for named outlets#32688
fix(router): support lazy loading for named outlets#32688asvishnyakov wants to merge 3 commits intoangular:masterfrom
Conversation
|
Also, possible fix #10981 |
|
Any update? |
|
@asvishnyakov Thank you for this, I hope Angular team will take their time to review those few lines of code before v9 is released (although, it might be too much to ask). Anyways, there are some indentation issues in |
|
This is still not working fully & #10981 (comment) is locked for some reason. Plz halp. |
|
Any updates on this ticket? |
In general, the router only matches and loads a single config tree. However, named outlets with empty paths are a special case where the router can and should actually match two different `Route`s and ensure that the modules are loaded for each match. This change updates the "ApplyRedirects" stage to ensure that named outlets with empty paths finish loading their configs before proceeding to the next stage in the routing pipe. This is necessary because if the named outlet has `loadChildren` but the associated lazy config is not loaded before following stages attempt to match and activate relevant `Route`s, an error will occur. fixes angular#12842
This comment has been minimized.
This comment has been minimized.
The internal tests have quite a few failures so this will require further investigation into why this change breaks them. |
|
@googlebot I consent |
|
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
|
I reviewed one of the failing tests and found that it fails because this finds all configs which match the url tree and loads each one if they have lazy children. The previous behavior would find and load only the first match. Generally, this would be fine because the router usually only activates a single config. Matches that appear earlier in the config take precedence (which is working as intended and documented). The failing provides an override to the real route so that it loads a no-op module. This change makes it so that the test override and the real i.e. In our case with these empty path named outlets, we have to load matched configs from each outlet. This approach also presents a problem because it will always load wildcard routes, which will always match the given url tree. At the moment, I can't really think of a solution to this. If no backwards compatible solution can be found, we could provide this as opt-in behavior in Edit: |
|
Closing in favor of #38379, as that one addresses the issues mentioned in #32688 (comment) |
|
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?
This is correct implementation and replacement of #25483
This PR is avoid problem appear in #25483: the same error occurs when you have lazy-loaded default route and routes with empty path and named outlet before it.
Given the following route configuration:
With this configuration, using the outlet as an entry point to the application, the root module will not load properly and results in the following error:
TypeError: Cannot read property 'routes' of undefined at getChildConfig (router.js:3041)The
_loadedConfigproperty of the route remainsundefinedas theexpandSegmentAgainstRoute()isn't executed.This issue is only present if the root has a lazy loaded module, works fine with a component or even with a lazy loaded module if the root path is not empty.
Issue Number: #12842
What is the new behavior?
Does this PR introduce a breaking change?
Other information