APP_BASE_HREF Multiple dynamic settings

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

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

common

Description

I have an admin page like this
image

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) {
this.app.setBaseHref('/fr')
this.router.navigate(['/foo'])
}

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 .
https://angular.io/guide/forms 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)[] = [];
constructor(
private _platformLocation: PlatformLocation,
@Optional() @Inject(APP_BASE_HREF) href?: string) {
super();
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-09-30
Star Count 84080
Watcher Count 3064
Fork Count 22235
Issue Count 1197

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
"Reset factory defaults" button 4 2022-04-14 2022-09-23
Pre-installation playbook failed on 1 2021-04-07 2022-07-26
N64 game not working 2 2022-02-07 2022-03-31
Add support for Jakarta 0 2022-05-04 2022-08-15
AirGap Connection via WalletConnect cannot be established 0 2022-04-13 2022-04-29
SelectLabelProps should use `div` instead of `label` 0 2022-04-25 2022-09-28
Add ANSSI recommendations on MFA and passwords 1 2021-10-08 2022-05-16
[Bug]: 胡桃数据库无法上传个人数据 1 2022-07-06 2022-09-13
(Minor) Destination Chain ID drop-down menu to deploy contract is in alphebetical, not numerical order 1 2021-08-12 2022-04-11
X-chain "done" button enabled too early 1 2021-07-16 2022-04-11
Leading decimals aren't accepted using transfer widget in amount field 1 2021-07-29 2022-04-11
Cannot reproduce cumulative frequency response of SincNet on Speaker-id 3 2020-02-03 2022-09-13
Misleading use of uint 1 2022-06-30 2022-09-02
Fetching property key with a period in the key 1 2022-04-07 2022-09-22
Changes to SETTINGS_NO_RFC7540_PRIORITIES 1 2021-10-06 2022-08-21
Support obtaining captures by name on `AnyRegexOutput` 0 2022-04-11 2022-08-15
Exporting schematics fails 6 2022-03-08 2022-09-15
Can't play .m4b: Unknown file format. 0 2021-04-20 2022-09-02
Running cellpose on colab - segmentation, finding masks on an image, and displaying results 1 2021-07-28 2022-09-24
k8s.pod.labels not up-to-date after labels are changed on kubernetes 4 2021-07-27 2022-09-01
cgroups paths are sometimes not parsed correctly when SystemdCgroup is not set in containerd configuration 0 2021-07-30 2022-01-13
[VSCode] - Have to locate SDK on myself 4 2021-05-07 2022-02-12
Remove sidebar swatches 1 2021-06-29 2022-09-01
Extending core block fields removes other blocks 1 2022-03-21 2022-07-16
Orchestrator: If image or containers creation is unsuccessful, return 5xx status 0 2021-09-29 2021-10-13
Add release notes to OnUpdateNotification content 0 2022-01-09 2022-09-28
Integrate NMON with linux pssdiag 0 2020-08-11 2022-09-07
Enhancement: Http 3 QUIC UDP Support 1 2021-11-11 2022-09-07
POST url loging 4 2021-04-21 2022-01-15
memtx TREE and HASH index `random` transaction management inconsistency 0 2022-09-12 2022-09-22
infra: rewrite `Default GCC CentOS 7` workflow 0 2022-09-10 2022-09-22
Dirty translations interface after emptying edits 1 2022-07-14 2022-09-05
Automate dependency workflow further 4 2021-10-07 2022-09-28
Make validation status of vaccination certificate more obvious 17 2021-07-15 2022-01-29
Bump nokogiri from 1.10.8 to 1.11.1 0 2021-02-17 2022-09-19
ie9是不能正常使用开关吗? 4 2020-05-19 2022-01-12
Assets not being recompiled after changes. 14 2016-01-16 2022-09-24
v2.2.x compilation fails on Ubuntu (with stock g++) 1 2019-12-31 2022-08-23
Bump requests from 2.25.1 to 2.26.0 0 2021-08-29 2022-07-03
Test 0 2021-06-24 2021-09-12
Test Create Milestone 0 2022-07-25 2022-09-19
UnboundLocalError 3 2022-01-03 2022-01-15
Cant add home.pl account (ver. 1.9.2) 1 2022-06-08 2022-09-22
Notifications, Email opens, clicks dont work 1 2022-04-09 2022-09-22
Doesn't load the names 2 3 2021-04-05 2022-09-28
Why is the redone p1 p2 inconsistent with the first p1 p2 result, compared to Sealed? 1 2022-07-07 2022-07-27
lotus daemon continuously printing 'error in RPC call to 'Filecoin.StateSectorExpiration': failed to find sector xxx' 6 2022-07-07 2022-07-27
GDPR overlay/modal is selected instead of the actual meaningful content on the page 3 2020-12-27 2022-09-29
Values inside 'as' patterns are disposed multiple times 1 2021-10-25 2022-08-30
[Windows Desktop] App does not read textfield characters when moving the cursor with arrow keys with screen reader enabled 3 2021-12-20 2022-08-27