-
Notifications
You must be signed in to change notification settings - Fork 43
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
Fix SSR flickering #28
Comments
I don't understand how it can help for the "flickering".
Do you think we have a problem because we return |
To avoid the flickering using Angular Universal we should add the router param InitialNavigation: 'enabled'. When you add this flag using this library or localize-router, you get the routing broken. You can see why this happens in the medium post
Also you can get more info in the issue of localize-router: If you don't add the InitialNavigation the SSR shows the rendered page, next you can see a blank page and finally you get back the rendered page. I don't know exactly why and where is the problem but I'm agree with you, seems to be something about the return, something like the function returned or if need a promise or a pure function, because several differences are between your implementation of AppInitialized and the described in the medium post. I'll continue investigating about it. |
@rafa-as |
I think that the point is mark as resolved the promise when the routes has been initialized calling the init method. export function initLanguage(injector: Injector): () => void {
return (): Promise<any> =>
new Promise((resolve) => {
injector.get(LocalizeRouterService).init();
resolve();
});
} |
Is it possible for you to try to replace appInitializer(): Promise<any> {
const res = this.parser.load(this.routes);
return res.then(() => {
const localize: LocalizeRouterService = this.injector.get(LocalizeRouterService);
localize.init();
});
} into |
@gilsdav I just tried it but doesn't works. The routes tree is not generated with the language prefix and the translations. The routes are accessible without /{lang} and with the translation key not the value. |
@rafa-as I've just tested the post and it doesn't work properly. For exemple this configuration will give an exception: If I understand, Angular use If we put one directly on |
What exception? Can you provide more info? I will test your route but we have equal routes in our three apps and everything works. |
more information on that topic |
@rafa-as is there a workaround on this issue? |
@hymenoby we have solved it with the following code: app.module.ts -> providers {
provide: LOCATION_INITIALIZED,
useFactory: initLanguageRoutes,
deps: [TranslateService, LocalizeParser, Router]
} app-routing.module.ts RouterModule.forRoot(
appRoutes,
{
scrollPositionRestoration: 'disabled',
anchorScrolling: 'enabled',
scrollOffset: [0, APP_CONSTANTS.contentTopOffset],
preloadingStrategy: SelectivePreloadingStrategy,
initialNavigation: 'enabled' // <---------- The important part
}
) language.service.ts export function initLanguageRoutes(translateService: TranslateService, localizeParser: LocalizeParser, router: Router): Promise<void> {
return new Promise((resolve: any) => {
// TODO: use constant default language
const lang = localizeParser.getLocationLang() || 'en';
concat(
translateService.use(lang).pipe(
filter(translations => !!translations),
first()
),
localizeParser.translateRoutes(translateService.currentLang).pipe(
first()
)
).subscribe(() => {
router.resetConfig(localizeParser.routes);
resolve();
});
});
} @gilsdav what do you think? we can add this logic inside the library? |
@rafa-as I tried to add the code but now the routes aren't translating any more here is my app.module.ts
and here is my routing.module.ts
After updating like this the routes aren't translated any more |
@hymenoby you should export LocalizeRouterModule in your routing file and I think that the APP_INITIALIZER provider should be uncommented. Normally is a good practice to import the AppRoutingModule the last one |
@rafa-as the problem is still not solved in my project, any page where i use a resolver to load data is no more working . |
@hymenoby you pages without a resolver works properly? |
@rafa-as , i tried the changes you were talking about and they didn't work, when i use them, the url without pages without resolver are not translated and the pages with a resolver have an error. i tried to make it work and i found a workaround for the pages without resolver, i found out that the problems occurs, when the parser does not find the translations to the routes (I think the language service is not loaded at that time or haven't loaded the language file yet). So i extended the default parser to have a parser with fallback translations in a constant (I've done it this way to not override the default process of the modules). so here is my new parser :
and in my app routing module :
with this parser with fallback translations, the routes without resolver are working but when i have a resolver on one route , it still gives me errors . Thank you for your support. |
any updates?? I'm stuck here, as lots of people, I think... |
Fixed by #70 |
@gilsdav hellooo I think it's working now!! I don't see any flirk and finally I can enable the 'initialNavigation' flag. I would like someone else to confirm it. Thanks for the fix David! |
Deployed in version |
The AppInitializer should be adapted to make work properly with Angular Universal + Lazy loaded modules.
I've tested a lot and this https://medium.com/@fessbespalov/enabling-initialnavigation-with-localizerouter-and-angular-universal-8d514f1faad9 solution works like a charm.
When this issue #26 is done we can start to make ngx-translate-router compatible 100% with Angular Universal and lazy loaded modules.
The text was updated successfully, but these errors were encountered: