Firebase SSR: lazy-loaded routes not working
Is the Universal with cloud functions example code still working? Trying to get it to work on an Angular 8 app and having no luck with lazy-loaded routes.
Version info
Angular: 8.2.9
Firebase: 7.17.1
AngularFire: 5.4.2
Other (e.g. Ionic/Cordova, Node, browser, operating system): Node: 10.22
How to reproduce these conditions
Created a new angular 8 app, added universal, added firebase and followed instructions on this repo for doing SSR from a cloud function. Here is the repo:
https://github.com/inorganik/ngx-countup-with-ssr/tree/firebase
Steps to set up and reproduce
clone the firebase branch, and npm i
npm run build - this builds client and server bundles, and functions
npm run serve:ssr - this works fine. you can test lazy loaded route as well http://localhost:4000/lazy
firebase serve - the root route works, but not the lazy loaded route.
Sample data and security rules
(not using firestore)
Debug output
** Errors in the JavaScript console **
Trying to visit the lazy-loaded route: http://localhost:5000/lazy - it throws:
Error: Cannot match any routes. URL Segment: 'ssr-demo-b3ef3/us-central1/ssr/main-es2015.34e6e6ac2c5785016cd0.js'
...followed by a long stack trace from functions in server.js
Somehow firebase's internal routing is being passed to angular server-side.
Expected behavior
it should server-side render the lazy-loaded route and serve it.
Actual behavior
It's throwing an error. Does not work deployed either.
This appears to be the same issue but the OP never explained how they solved the issue. https://github.com/firebase/firebase-tools/issues/1890
Hi there, did you find a solution to this? I am facing the same issue on angular 10 too.
Routing doesn't even work at all when I deploy but works on localhost serve
Thanks,
Ah interesting the path stuff makes sense, would be the culprit. I'll see about getting a mitigation in for 6.1.1
Provide an APP_BASE_HREF from @angular/core in your server module should get ya up and running.
I'm using
{ provide: APP_BASE_HREF, useFactory: () => isDevMode() ? '/us-central1/ssr' : '/ssr' }
@jamesdaniels I have tried APP_BASE_HREF fix, but the problem has not been solved.
All my feature-modules where loaded with lazy-lading, and I have solved the problem loding the first one with "eager-loading", but I think this is a patch...