Skip to content

Commit 1600687

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 be23b7c commit 1600687

File tree

14 files changed

+468
-629
lines changed

14 files changed

+468
-629
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",

goldens/size-tracking/integration-payloads.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"cli-hello-world-lazy": {
2727
"uncompressed": {
2828
"runtime": 2734,
29-
"main": 231018,
29+
"main": 225309,
3030
"polyfills": 33810,
3131
"src_app_lazy_lazy_routes_ts": 487
3232
}

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
},
@@ -473,9 +470,6 @@
473470
{
474471
"name": "NoMatch"
475472
},
476-
{
477-
"name": "NoMatch2"
478-
},
479473
{
480474
"name": "NodeInjector"
481475
},
@@ -734,9 +728,6 @@
734728
{
735729
"name": "TakeSubscriber"
736730
},
737-
{
738-
"name": "TakeWhileSubscriber"
739-
},
740731
{
741732
"name": "TapSubscriber"
742733
},
@@ -1061,12 +1052,18 @@
10611052
{
10621053
"name": "createRoot"
10631054
},
1055+
{
1056+
"name": "createSegmentGroupFromRoute"
1057+
},
10641058
{
10651059
"name": "createTView"
10661060
},
10671061
{
10681062
"name": "createTemplateRef"
10691063
},
1064+
{
1065+
"name": "createUrlTreeFromSegmentGroup"
1066+
},
10701067
{
10711068
"name": "currentConsumer"
10721069
},
@@ -1346,9 +1343,6 @@
13461343
{
13471344
"name": "getOrCreateNodeInjectorForNode"
13481345
},
1349-
{
1350-
"name": "getOrCreateRouteInjectorIfNeeded"
1351-
},
13521346
{
13531347
"name": "getOrCreateTNode"
13541348
},
@@ -1556,9 +1550,6 @@
15561550
{
15571551
"name": "isFunction2"
15581552
},
1559-
{
1560-
"name": "isImmediateMatch"
1561-
},
15621553
{
15631554
"name": "isInlineTemplate"
15641555
},
@@ -1622,9 +1613,6 @@
16221613
{
16231614
"name": "joinWithSlash"
16241615
},
1625-
{
1626-
"name": "last"
1627-
},
16281616
{
16291617
"name": "last2"
16301618
},
@@ -1727,9 +1715,6 @@
17271715
{
17281716
"name": "ngZoneApplicationErrorHandlerFactory"
17291717
},
1730-
{
1731-
"name": "noLeftoversInUrl"
1732-
},
17331718
{
17341719
"name": "noMatch"
17351720
},
@@ -1862,9 +1847,6 @@
18621847
{
18631848
"name": "saveNameToExportMap"
18641849
},
1865-
{
1866-
"name": "scan"
1867-
},
18681850
{
18691851
"name": "scheduleArray"
18701852
},
@@ -1940,9 +1922,6 @@
19401922
{
19411923
"name": "shouldSearchParent"
19421924
},
1943-
{
1944-
"name": "sortByMatchingOutlets"
1945-
},
19461925
{
19471926
"name": "split"
19481927
},

0 commit comments

Comments
 (0)