Skip to content

Commit bfea80d

Browse files
atscottAndrewKushnir
authored andcommitted
refactor(router): Simplify location strategy providers (angular#46215)
Rather than using a `provideLocationStrategy` function, the `useHash` can simply provide one strategy or another. The current factory function does not change how the dependencies are used. PR Close angular#46215
1 parent d7a7983 commit bfea80d

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

packages/router/src/router_module.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,7 @@ export class RouterModule {
136136
deps: [[Router, new Optional(), new SkipSelf()]]
137137
},
138138
{provide: ROUTER_CONFIGURATION, useValue: config ? config : {}},
139-
{
140-
provide: LocationStrategy,
141-
useFactory: provideLocationStrategy,
142-
deps:
143-
[PlatformLocation, [new Inject(APP_BASE_HREF), new Optional()], ROUTER_CONFIGURATION]
144-
},
139+
config?.useHash ? provideHashLocationStrategy() : providePathLocationStrategy(),
145140
{
146141
provide: RouterScroller,
147142
useFactory: createRouterScroller,
@@ -187,10 +182,12 @@ export function createRouterScroller(
187182
return new RouterScroller(router, viewportScroller, config);
188183
}
189184

190-
export function provideLocationStrategy(
191-
platformLocationStrategy: PlatformLocation, baseHref: string, options: ExtraOptions = {}) {
192-
return options.useHash ? new HashLocationStrategy(platformLocationStrategy, baseHref) :
193-
new PathLocationStrategy(platformLocationStrategy, baseHref);
185+
function provideHashLocationStrategy(): Provider {
186+
return {provide: LocationStrategy, useClass: HashLocationStrategy};
187+
}
188+
189+
function providePathLocationStrategy(): Provider {
190+
return {provide: LocationStrategy, useClass: PathLocationStrategy};
194191
}
195192

196193
export function provideForRootGuard(router: Router): any {

0 commit comments

Comments
 (0)