Skip to content

Commit 3c7e637

Browse files
committed
fix(router): Route matching should only happen once when navigating (#49163)
When navigating in the Router, the current approach does the redirects and the creation of the `RouterStateSnapshot` in two separate steps (applyRedirects and recognize). These two steps duplicate the route matching logic, resulting in user code on routes being executing twice (custom `UrlMatcher` and `canMatch` guards). This also duplicates the complex matching logic in two places, which increases the bundle size and maintenance burden. This commit combines the `applyRedirects` and `recognize` steps into a single matching algorithm. fixes #26081 PR Close #49163
1 parent 2d25a2d commit 3c7e637

File tree

13 files changed

+467
-628
lines changed

13 files changed

+467
-628
lines changed

goldens/circular-deps/packages.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,6 @@
286286
"packages/forms/src/validators.ts",
287287
"packages/forms/src/model/abstract_model.ts"
288288
],
289-
[
290-
"packages/router/src/apply_redirects.ts",
291-
"packages/router/src/operators/check_guards.ts",
292-
"packages/router/src/navigation_transition.ts",
293-
"packages/router/src/operators/apply_redirects.ts"
294-
],
295289
[
296290
"packages/router/src/directives/router_outlet.ts",
297291
"packages/router/src/router_outlet_context.ts"
@@ -311,7 +305,7 @@
311305
],
312306
[
313307
"packages/router/src/navigation_transition.ts",
314-
"packages/router/src/operators/apply_redirects.ts"
308+
"packages/router/src/operators/check_guards.ts"
315309
],
316310
[
317311
"packages/router/src/navigation_transition.ts",

packages/core/test/bundling/router/bundle.golden_symbols.json

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
{
3333
"name": "ApplicationRef"
3434
},
35-
{
36-
"name": "ApplyRedirects"
37-
},
3835
{
3936
"name": "ArgumentOutOfRangeError"
4037
},
@@ -476,9 +473,6 @@
476473
{
477474
"name": "NoMatch"
478475
},
479-
{
480-
"name": "NoMatch2"
481-
},
482476
{
483477
"name": "NodeInjector"
484478
},
@@ -740,9 +734,6 @@
740734
{
741735
"name": "TakeSubscriber"
742736
},
743-
{
744-
"name": "TakeWhileSubscriber"
745-
},
746737
{
747738
"name": "TapSubscriber"
748739
},
@@ -1067,12 +1058,18 @@
10671058
{
10681059
"name": "createRoot"
10691060
},
1061+
{
1062+
"name": "createSegmentGroupFromRoute"
1063+
},
10701064
{
10711065
"name": "createTView"
10721066
},
10731067
{
10741068
"name": "createTemplateRef"
10751069
},
1070+
{
1071+
"name": "createUrlTreeFromSegmentGroup"
1072+
},
10761073
{
10771074
"name": "currentConsumer"
10781075
},
@@ -1352,9 +1349,6 @@
13521349
{
13531350
"name": "getOrCreateNodeInjectorForNode"
13541351
},
1355-
{
1356-
"name": "getOrCreateRouteInjectorIfNeeded"
1357-
},
13581352
{
13591353
"name": "getOrCreateTNode"
13601354
},
@@ -1562,9 +1556,6 @@
15621556
{
15631557
"name": "isFunction2"
15641558
},
1565-
{
1566-
"name": "isImmediateMatch"
1567-
},
15681559
{
15691560
"name": "isInlineTemplate"
15701561
},
@@ -1628,9 +1619,6 @@
16281619
{
16291620
"name": "joinWithSlash"
16301621
},
1631-
{
1632-
"name": "last"
1633-
},
16341622
{
16351623
"name": "last2"
16361624
},
@@ -1733,9 +1721,6 @@
17331721
{
17341722
"name": "ngZoneApplicationErrorHandlerFactory"
17351723
},
1736-
{
1737-
"name": "noLeftoversInUrl"
1738-
},
17391724
{
17401725
"name": "noMatch"
17411726
},
@@ -1868,9 +1853,6 @@
18681853
{
18691854
"name": "saveNameToExportMap"
18701855
},
1871-
{
1872-
"name": "scan"
1873-
},
18741856
{
18751857
"name": "scheduleArray"
18761858
},
@@ -1946,9 +1928,6 @@
19461928
{
19471929
"name": "shouldSearchParent"
19481930
},
1949-
{
1950-
"name": "sortByMatchingOutlets"
1951-
},
19521931
{
19531932
"name": "split"
19541933
},

0 commit comments

Comments
 (0)