mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(router): Simplify location strategy providers (#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 #46215
This commit is contained in:
committed by
Andrew Kushnir
parent
d7a7983a0a
commit
bfea80d19f
@@ -136,12 +136,7 @@ export class RouterModule {
|
||||
deps: [[Router, new Optional(), new SkipSelf()]]
|
||||
},
|
||||
{provide: ROUTER_CONFIGURATION, useValue: config ? config : {}},
|
||||
{
|
||||
provide: LocationStrategy,
|
||||
useFactory: provideLocationStrategy,
|
||||
deps:
|
||||
[PlatformLocation, [new Inject(APP_BASE_HREF), new Optional()], ROUTER_CONFIGURATION]
|
||||
},
|
||||
config?.useHash ? provideHashLocationStrategy() : providePathLocationStrategy(),
|
||||
{
|
||||
provide: RouterScroller,
|
||||
useFactory: createRouterScroller,
|
||||
@@ -187,10 +182,12 @@ export function createRouterScroller(
|
||||
return new RouterScroller(router, viewportScroller, config);
|
||||
}
|
||||
|
||||
export function provideLocationStrategy(
|
||||
platformLocationStrategy: PlatformLocation, baseHref: string, options: ExtraOptions = {}) {
|
||||
return options.useHash ? new HashLocationStrategy(platformLocationStrategy, baseHref) :
|
||||
new PathLocationStrategy(platformLocationStrategy, baseHref);
|
||||
function provideHashLocationStrategy(): Provider {
|
||||
return {provide: LocationStrategy, useClass: HashLocationStrategy};
|
||||
}
|
||||
|
||||
function providePathLocationStrategy(): Provider {
|
||||
return {provide: LocationStrategy, useClass: PathLocationStrategy};
|
||||
}
|
||||
|
||||
export function provideForRootGuard(router: Router): any {
|
||||
|
||||
Reference in New Issue
Block a user