-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Browser button navigation for remote app routes #215
Comments
While listening to the router events this is what I have come across : On the popstate (browser back button clicked to go to home/client-configuration) it looks like the remote app router instance runs an imperative route to (home/my-clients path) which should have never happened (and loads the content of home/my-clients) and meanwhile the shell app router instance tries to run popstate on the right url path. Is there any way we can connect the two routers to work in sync? |
I made a PR #217 for this, but I found that the only way to get the route correctly handled is to do it during ngOnInit. export class MfeComponent implements OnInit {
constructor(private router: Router, private location: Location) {}
ngOnInit() {
this.router.initialNavigation();
void this.router.navigateByUrl(this.location.path(true));
}
} |
So does this mean this change has to be done to each and every component (which has routes) in the remote app ? |
Only on first level components : the ones that are federated. Not inner ones. |
Actually, there are two bugs.
My PR fixes the first one, but my suggestion to move connectRouter in component fixes the second one. |
@manfredsteyer Is this actually solved? Are there any docs about this issue? |
Not really. @brunoalod Look at issue 451 |
Hey there @RajathVenkatesh Thanks to your PR and some hours reading angular/router and mf-tools plugin, I came to a possible solution. First, I removed And then I added this inside // AppComponent
import { Location } from '@angular/common';
// ...
export class AppComponent implements OnInit, OnDestroy {
private nonRouterCurrentEntryChangeSubscription?: SubscriptionLike;
customInitialNavigation() {
const url = `${location.pathname.substring(1)}`;
this.router.navigateByUrl(url);
this.nonRouterCurrentEntryChangeSubscription ??= this.location.subscribe(event => {
if (event['type'] === 'popstate') {
const routeBelongsThisRouter = event.url!.startsWith('/search'); // here goes the url you use in startsWith() on shell *
if (routeBelongsThisRouter) {
this.router.navigateByUrl(event['url']!, { state: event.state });
}
}
})
}
ngOnInit() {
this.customInitialNavigation();
// ...
}
} The first two lines were exctracted from your PR and correspond to the initial navigation (but fixed) made by The ngOnDestroy(): void {
if (this.nonRouterCurrentEntryChangeSubscription) {
this.nonRouterCurrentEntryChangeSubscription.unsubscribe();
this.nonRouterCurrentEntryChangeSubscription = undefined;
}
} This is also part of @angular/router's
Hope this helps |
Good Day!
We have two Angular apps where the remote app is used as a MFE web component wrapper in the shell app.
And it looks like multiple router states get created even after sharing the @angular/router in webpack.
This leads to the browser back and forward buttons not working! (The popstate tracking is a bit messed up)
Please can someone help me with a solution or a work around?
The text was updated successfully, but these errors were encountered: