-
Notifications
You must be signed in to change notification settings - Fork 95
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
Lazy loading not working for nested lazy routes #45
Comments
Can you suggest a temporary workaround? |
At the moment unfortunately not, except for not using lazy loading. |
Hi, to me looks like it is not working with any child route. Can you confirm? |
@NKjoep What do you mean by "any child route"? |
I meant not lazy loaded child route. However I think I fixed the issue I had. I ended with a broken configuration. |
Hi, do you have any updates for this issue ? |
A work around to this is to add a route in others translation language. If you have many languages and many subroutes that can be painfull but if like me you have to translate 2 languages, you're going to be able to use lazyloading and copy paste urls that the users can enter in the browser to arrive directly on the web page. For Exemple: In appModule In submodule: export const routes: Routes = [ fr.sjon : en.json: |
@Messilius thanks for the tip! have you actually tried that already? :) does it work? |
It work in the project im currently doing. The only thing that dont work is when there is 2 subsequent lazymodule than a lazy child. But with one layer of lazy loading and then child components it work. |
Any update on this? It's a problem of angular or a problem of this module? |
It's dependent on angular updating the router, here's the issue: angular/angular#16282 Latest comment from the angular team here: angular/angular#16308 (comment) |
Dear Meeroslav, I'm stuck with this problem of child routes and lazy loading. I have made a GIT that reproduce exactly the problem (if it can help you)... Here is it : https://github.com/MisterEffix/localize-router-and-sub-routing |
As I commented before in some other PR, if you look at this fn from the sources: /**
* Change language and navigate to translated route
* @param lang
* @param extras
*/
LocalizeRouterService.prototype.changeLanguage = function (lang, extras) {
var _this = this;
if (lang !== this.parser.currentLang) {
var rootSnapshot_1 = this.router.routerState.snapshot.root;
this.parser.translateRoutes(lang).subscribe(function () {
_this.router.navigateByUrl(_this.traverseRouteSnapshot(rootSnapshot_1), extras);
});
}
}; Everything is ok (page stays the same and translations are in place) until the What do you think? (ps = also I'd use a take(1) there --> |
Has there been any resolution to this? |
Finally yes. I will implement the solution in the upcoming days. |
Currently having the same issue as mentioned here. I'm curious about the solution you came up with. |
My production build is always broken and i get a 404 when loading the lazyloaded frontpage. I get a 404 when loading the page. Everything works when not creating a production build. |
any updates on this one? I mean, no pressure :) |
@marko999, this bug was fixed and closed 4 days ago. Please upgrade to version There will be a public github page soon. Let me know if there is anything else I can help you with. |
Thanks for fixing the bug! I haven't had time to check out the new version yet but do you think there will be any problems with extending your |
@CamusAran, it's safe to extend Maybe you'd like to propose improvement of the |
@meeroslav I did think about suggesting that but I don't know if it is in within the scope of the package. Ideally it'd be implemented upstream but that issue is over a year old now. What do you think? |
@CamusAran generally, it's not within the scope of this package. But then again, having conflict with another loader is not desired behavior either. If you think this error handling is still needed, we can make LocalizeRouterConfigLoader extendable and replaceable. That way you can create external package for people that need error handling. |
@meeroslav Thanks, I'll get back to you once I've had a chance to work on it (most likely next year). |
Still doesn't work for me, |
This also still does not work for me... It appears once I successfully navigate to the route in one language, it will start working for the others. For instance, the route in English is But if I try to navigate to the route by the localized value (not the exact value specified in the url: "/fr/search-fr/resultsfr"
urlAfterRedirects: "/fr/search-fr" |
Looking at the When I do the same for my lazy loaded module, there is no |
I fixed my problem by creating explicit routing modules which get imported into the main module like the ex: core-router.module.ts // module that imports and exports RouterModule and LocalizeRouterModule
core.module.ts // imports CoreRouterModule This did create a new issue when trying to load the lazy module... This is currently being discussed (with a temporary fix) here: angular/angular-cli#8917 (comment) |
I have dig a little bit more why doesn't work in my case and found out that this line:
will skip route configuration when lazy module has default route set as empty with parent component in, something like this:
|
can we reopen this issue @meeroslav ? or I can create a new issue with repro... |
I had the same issue too, it has been a year, too bad that it's not fixed yet. |
@meeroslav some news here? |
@meeroslav changeLanguage executed on the path lazyModulePath/child1 will not work. some news here? |
I just started using Angular. Very sad to see such problem is still not fixed for more than a year. I am looking for solution for a similar problem. lazyModulePath/:parameter |
Even if this was resolved at any point of time, there had to be a regression. As of today only top level route of a lazy-loaded module (the one with empty string path) is loaded properly, any child routes it contains resolve in |
The issue seems to come back with the upgrade to Angular 6. I have the same issue. When changing language, the component reload (it occurs when hitting The function : EDIT : After fixing the function
|
The issue should be resolved in both 1.0.1 version (for Angular 4.0.0-5.2.5) and 2.0.0-RC.1 (for Angular 6/7) There was a bug in path traversing when translating the full route. |
It worked for me in the version 2.0.0-RC.2 (for Angular 6/7) but it doesn't in the 2.0.0-RC.1 but i'm glad that its solved. Thanks a lot guys! |
Looks like this is not working with nested lazy loading... top level lazy loaded components get loaded but lazy loaded components with routes declared with forChild(routes) get the "Cannot match any routes" error Here's an example where the terms/privacy policy page work as expected but the lazy loaded module breaks with the Cannot match any routes error:
And here's the lazy loaded module's routes:
|
Are there any updates on this? I'm having the same issue aswell. Here is my lazy loaded module routing: export const routes: Routes = [
{
path: '',
component: AuthDashboardPage,
children: [
{
path: '',
loadChildren: () => import('../reservations/reservations.module').then(m => m.ReservationsModule)
},
{
path: 'profile',
loadChildren: () => import('../profile/profile.module').then(m => m.ProfileModule)
}
]
}
]; My first child route with the empty path (ReservationsModule) gets loaded correctly, but the second path "profile" does not. It redirects to the home page. Here is my lazy loaded module: @NgModule({
imports: [SharedModule, LocalizeRouterModule.forChild(routes), routing, ...materialModules],
exports: [],
declarations: [AuthDashboardPage],
providers: []
})
export class AuthDashboardModule {} |
@timmyrosen I did make it work. |
@timmyrosen This library seems to be dead, we have tried all the suggested fixes in this library but none works. We already migrated to https://github.com/gilsdav/ngx-translate-router and everything works like a charm with a good maintainer support. Also works completely with Angular Universal. |
Hello, |
IIRC, I could only get it working by specifying a path for everything.
And the package.json is here:
|
@ProfessorManhattan This do not work in my project, i am on angular 8 and i use angular-universal for SSR , the app works fine if i dont set the initial navigation to true, bu when i do, if i try to access directly to any page other than the root page i get a route not found error here is my package.json
|
@ProfessorManhattan @hymenoby check my previous comment: #45 (comment) I encourage you to migrate ASAP. This project seems to be dead and doesn't work for sure with SSR and lazy load nested routes. |
@ProfessorManhattan Thanks, i will try with https://github.com/gilsdav/ngx-translate-router as you said |
Note that at the moment lazy loading doesn't work for nested routes. If you have route like lazy/lazy_child if you navigate first to lazy and then to lazy_child everything will work. However if you go directly to lazy/lazy_child Router will report unknown route error, since child routes will not be translated before Route matching mechanism kicks in.
Steps to reproduce
/lazy/child
in language other thanen
e.g.Current behavior
Router reports NavigationError as route has not been translated at the moment of route matching.
Expected behavior
All child lazy routes should be translated and Router should properly find requested route.
Explanation
LocalizeRouter currently listens to RouteConfigLoadEnd, but this event only signals that child module has been loaded. Child routes are still not available. Additionally
RouteConfigLoadEnd
returns only requested route, not the module factory from which the child routes could be extracted.Further steps
Discuss with Angular team on possible solutions.
The text was updated successfully, but these errors were encountered: