简体   繁体   English

Firebase SSR:延迟加载的路由不起作用

[英]Firebase SSR: lazy loaded routes not working

I have an Angular 8 project with one lazy-loaded route.我有一个 Angular 8 项目,其中包含一条延迟加载的路线。 I have added Universal via the ng add @nguniversal/express-engine command.我通过ng add @nguniversal/express-engine命令添加了 Universal。 Building and serving the app works fine.构建和服务应用程序工作正常。

I added firebase and set up SSR via a cloud function, partially following the guide on the angularfire repo which appears to be outdated.我添加了 firebase 并通过云 function 设置 SSR,部分遵循似乎已过时的angularfire repo指南。

Serving the app with serve:ssr , it works fine and requesting the lazy-loaded route works as well.使用serve:ssr为应用程序提供服务,它可以正常工作,并且请求延迟加载的路由也可以。 But when testing with firebase serve , it only works until you request a lazy loaded route, (eg, refresh page on lazy-loaded route) then an error is thrown:但是在使用firebase serve进行测试时,它只在您请求延迟加载路由(例如,在延迟加载路由上刷新页面)之前有效,然后抛出错误:

ERROR { Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'ssr-demo-b3ef3/us-central1/ssr'
>  Error: Cannot match any routes. URL Segment: 'ssr-demo-b3ef3/us-central1/ssr'
>      at router_ApplyRedirects.noMatchError (/Users/jamieperkins/Web-projects/GitHub/ngx-countup-with-ssr/functions/dist/webpack/server.js:149267:16)
>      at catchError_CatchSubscriber.urlTrees$.pipe.catchError [as selector] (/Users/jamieperkins/Web-projects/GitHub/ngx-countup-with-ssr/functions/dist/webpack/server.js:149231:28)

When deployed, the function crashes when the lazy-loaded route is requested.部署后,当请求延迟加载路由时,function 崩溃。

The code is all on github in this repo (firebase branch):https://github.com/inorganik/ngx-countup-with-ssr/tree/firebase代码全部在此仓库(firebase 分支)中的 github 上:https://github.com/inorganik/ngx-countup-with-ssr/tree/firebase

To reproduce, clone the repo and do the following:要重现,请克隆 repo 并执行以下操作:

npm i
npm run build
npm run serve:ssr

should all work fine.应该一切正常。 But you try但是你试试

firebase serve

and request the lazy-loaded route you'll get the error.并请求延迟加载的路由,您将收到错误消息。

Angularfire issue here . Angularfire 问题在这里 firebase-tools issue here . firebase-tools 问题在这里

I would strongly suggest that you update your project to use the latest stable version of Angular and the @nguniversal/express-engine.我强烈建议您更新您的项目以使用 Angular 和 @nguniversal/express-engine 的最新稳定版本。 get back to me if this solved your issue or that you for some reason are unable to update your project.如果这解决了您的问题或您由于某种原因无法更新您的项目,请回复我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM