-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
fix(router): Router.createUrlTree should work with any ActivatedRoute #48508
Conversation
26aa5de
to
6894da9
Compare
6894da9
to
2f187c8
Compare
…6 release v16 will have a breaking change to the way `UrlTree`s are constructed. This change is actually a bug fix that makes `UrlTree` creation correct in more scenarios (see angular#48508). However, this can affect applications that are relying on the current incorrect behavior. This commit adds a dev mode warning when the target of a navigation will change once angular#48508 is submitted.
…6 release v16 will have a breaking change to the way `UrlTree`s are constructed. This change is actually a bug fix that makes `UrlTree` creation correct in more scenarios (see angular#48508). However, this can affect applications that are relying on the current incorrect behavior. This commit adds a dev mode warning when the target of a navigation will change once angular#48508 is submitted.
…6 release v16 will have a breaking change to the way `UrlTree`s are constructed. This change is actually a bug fix that makes `UrlTree` creation correct in more scenarios (see angular#48508). However, this can affect applications that are relying on the current incorrect behavior. This commit adds a dev mode warning when the target of a navigation will change once angular#48508 is submitted.
…6 release v16 will have a breaking change to the way `UrlTree`s are constructed. This change is actually a bug fix that makes `UrlTree` creation correct in more scenarios (see angular#48508). However, this can affect applications that are relying on the current incorrect behavior. This commit adds a dev mode warning when the target of a navigation will change once angular#48508 is submitted.
…6 release (#48688) v16 will have a breaking change to the way `UrlTree`s are constructed. This change is actually a bug fix that makes `UrlTree` creation correct in more scenarios (see #48508). However, this can affect applications that are relying on the current incorrect behavior. This commit adds a dev mode warning when the target of a navigation will change once #48508 is submitted. PR Close #48688
2f187c8
to
1548a4d
Compare
1548a4d
to
f76d0d8
Compare
This change makes the `createUrlTreeFromSnapshot` added in angular#45877 the default and only behavior in the Router. This now addreses angular#42191, angular#38276, angular#22763, and angular#48472 without needing to create custom handling to call `createUrlTreeFromSnapshot` (since it's now called by `Router.createUrlTree`). BREAKING CHANGE: Tests which mock `ActivatedRoute` instances may need to be adjusted because Router.createUrlTree now does the right thing in more scenarios. This means that tests with invalid/incomplete ActivatedRoute mocks may behave differently than before. Additionally, tests may now navigate to a real URL where before they would navigate to the root. Ensure that tests provide expected routes to match. There is rarely production impact, but it has been found that relative navigations when using an `ActivatedRoute` that does not appear in the current router state were effectively ignored in the past. By creating the correct URLs, this sometimes resulted in different navigation behavior in the application. Most often, this happens when attempting to create a navigation that only updates query params using an empty command array, for example `router.navigate([], {relativeTo: route, queryParams: newQueryParams})`. In this case, the `relativeTo` property should be removed.
f76d0d8
to
8d2e92f
Compare
caretaker note: This is already patched into g3. The patch should be updated since we have 1 team currently migrating off of the old strategy (cl/512727208) |
This PR was merged into the repository by commit 31f210b. |
We started receiving the warning that the behavior will change, but are concerned that we are in a usecase that has not been tested/thought of. We are not using the router just to update query params in place, but instead are heavily leveraging named router outlets (not at the root). We have a centralized call to update the named router outlets with a call like: this.router.navigate([{ outlets }], { //updates the named router outlets to the new sub-routes
relativeTo: this.activatedRoute
queryParams: {
layout: layout
},
queryParamsHandling: 'merge',
}); This causes the following warning to be emitted:
If this is indeed true and a breaking change, this will cause our whole routing solution to break. I feel like this may be an oversight. When I remove the call to update the Also, if I call navigate with the route path included: this.router.navigate(['/case/justin/test', { outlets }], { //updates the named router outlets to the new sub-routes
relativeTo: this.activatedRoute
queryParams: {
layout: layout
},
queryParamsHandling: 'merge',
}); We receive the warning:
This leads me to believe that something is overlooked regarding using named router outlets. Could you please advise? |
@justinrassier Can you please create a stackblitz to demonstrate this? |
@atscott my coworker and I will work on getting you one ASAP. It's a bit of a complicated setup so it may take a little effort to recreate. Thanks for the quick response! |
@justinrassier Thanks. It's a bit hard to know your exact situation without having a reproduction. I was able to reproduce the exact warning based on my experience with debugging breakages internally but I can't really know if this is what your app is doing: https://stackblitz.com/edit/angular-jixxmu?file=src%2Fmain.ts Look out for a navigation in |
@atscott Thanks for the details, we really appreciate it! We have a stackblitz with what we thought was our situation, but are not able to reproduce the error. We will dig into the details you provided here and maybe it can give us some insights into what our real app has going wrong. The good news is that our architecture/setup should continue to be supported! We just need to figure out what we could be doing to cause the warning to show. One question, would this also crop up if you did not pass in a |
Yes, it absolutely can come up without using It might be helpful to put a breakpoint at the place where the warning is getting created and check if the resulting URL makes sense based on the inputs: angular/packages/router/src/create_url_tree_strategy.ts Lines 25 to 35 in 35f4918
|
Great tips @atscott thanks. I will have to dig in more when I get back on Monday, but this is a top priority for me to figure out so we don't get stuck on an old version of Angular. We aren't doing any navigation inside of Again, I really appreciate your time and your troubleshooting tips. I'l see what I can find out! |
@justinrassier The So it's pretty similar to a navigation in |
I am unsure what component would no longer exist in our case. (most) of our navigation triggers from a shell component that always exists, which still gets the error. And the Another confusing part is this actually was originally found when I was fixing up some tests in the upgrade and saw the console warning there. In this case, we are not testing any of the components, just the services and effects that run from tirggered actions in ngrx land (and router events). We are also not mocking any router pieces as part of this test, we are using the full So on Monday I will try taking the Stackblitz we have been working on and adding in ngrx and the router store to see if I can get a full mini implementation of all of our moving pieces. |
@atscott finally got a reproduction. The addition of ngrx and router-store were all a red herring. It appears to be a problem that crops up when you have a router configuration that has a nested route with a https://stackblitz.com/edit/angular-nssbq3?file=src/main.ts If we are doing something wrong, please let us know so we can resolve it before this becomes a blocker. Although it does feel like we may have stumbled across something that was not caught or thought of. Thanks for all your help! |
@justinrassier This is indeed a bug in the new implementation - I should have a fix for this soon. By the way, I think your use of |
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. |
This change makes the
createUrlTreeFromSnapshot
added in #45877 thedefault and only behavior in the Router. This now addreses #42191, #38276, #22763,
and #48472 without needing to create custom handling to
call
createUrlTreeFromSnapshot
(since it's now called byRouter.createUrlTree
).BREAKING CHANGE: Tests which mock
ActivatedRoute
instances may need to be adjustedbecause Router.createUrlTree now does the right thing in more
scenarios. This means that tests with invalid/incomplete ActivatedRoute mocks
may behave differently than before. Additionally, tests may now navigate
to a real URL where before they would navigate to the root. Ensure that
tests provide expected routes to match.
There is rarely production impact, but it has been found that relative
navigations when using an
ActivatedRoute
that does not appear in thecurrent router state were effectively ignored in the past. By creating
the correct URLs, this sometimes resulted in different navigation
behavior in the application. Most often, this happens when attempting to
create a navigation that only updates query params using an empty
command array, for example
router.navigate([], {relativeTo: route, queryParams: newQueryParams})
. In this case, therelativeTo
propertyshould be removed.