APP_BASE_HREF Multiple dynamic settings

This issue has been tracked since 2022-09-08.

Which @angular/* package(s) are relevant/related to the feature request?



I have an admin page like this

I want to reset APP_BASE_HREF when I choose a language

Don't want to use window.location.href to refresh the page

Proposed solution

Could you please provide a function to reset it?

looks like:

constructor(private app: App) {'/fr')

If there is another way that is better, sorry I haven't used angular very long

Alternatives considered

dynamic change APP_BASE_HREF

yoonasy wrote this answer on 2022-09-08

or custom redirectTo support Guard

redirect(toUrl) {
  if(toUrl.startWiths('/fr')) {
    return true
  } else {
    this.router.navigate(['/fr' + toUrl])
  return true
RAJEEV2510 wrote this answer on 2022-09-08

You can do with routing and routerLink ,it will work for your scenerio for more . in this website url change without refresh .

atscott wrote this answer on 2022-09-19

Dynamically changing the value of APP_BASE_HREF isn't possible and won't be something we'll do. However, what you're requesting can generally be accomplished with a custom LocationStrategy implementation. Here's how it's used in the provided PathLocationStrategy:

private _baseHref: string;
private _removeListenerFns: (() => void)[] = [];
private _platformLocation: PlatformLocation,
@Optional() @Inject(APP_BASE_HREF) href?: string) {
this._baseHref = href ?? this._platformLocation.getBaseHrefFromDOM() ??
inject(DOCUMENT).location?.origin ?? '';

Your custom strategy can instead read from a service which provides a base href value that you can change programatically.

More Details About Repo
Owner Name angular
Repo Name angular
Full Name angular/angular
Language TypeScript
Created Date 2014-09-18
Updated Date 2022-10-05
Star Count 84152
Watcher Count 3063
Fork Count 22247
Issue Count 1203


Issue Title Created Date Updated Date