我正在运行.net Core webpack 3 Angular 4.
在应用程序内部使用时,我的延迟加载工作得很好,就像通过导航栏一样
但是当我尝试直接访问延迟加载的URL时失败了.
fail: Microsoft.AspNetCore.NodeServices[0]
ERROR { Error: Uncaught (in promise): Error: Cannot find module './components/members/members.module.ngfactory'.
Error: Cannot find module './components/members/members.module.ngfactory'.
at /root/myApp/bin/Release/netcoreapp2.0/publish/ClientApp/dist/vendor.js:35933:9
at ZoneDelegate.module.exports.ZoneDelegate.invoke (/root/myApp/bin/Release/netcoreapp2.0/publish/ClientApp/dist/vendor.js:92811:26)
at Object.onInvoke (/root/myApp/bin/Release/netcoreapp2.0/publish/ClientApp/dist/vendor.js:14833:33)
at ZoneDelegate.module.exports.ZoneDelegate.invoke (/root/myApp/bin/Release/netcoreapp2.0/publish/ClientApp/dist/vendor.js:92810:32)
at Zone.module.exports.Zone.run (/root/myApp/bin/Release/netcoreapp2.0/publish/ClientApp/dist/vendor.js:92561:43)
at /root/myApp/bin/Release/netcoreapp2.0/publish/ClientApp/dist/vendor.js:93238:57
at ZoneDelegate.module.exports.ZoneDelegate.invokeTask (/root/myApp/bin/Release/netcoreapp2.0/publish/ClientApp/dist/vendor.js:92844:31)
at Object.onInvokeTask (/root/myApp/bin/Release/netcoreapp2.0/publish/ClientApp/dist/vendor.js:14824:33)
at ZoneDelegate.module.exports.ZoneDelegate.invokeTask (/root/myApp/bin/Release/netcoreapp2.0/publish/ClientApp/dist/vendor.js:92843:36)
at Zone.module.exports.Zone.runTask (/root/myApp/bin/Release/netcoreapp2.0/publish/ClientApp/dist/vendor.js:92611:47)
…
是否有针对此问题的已知修复或解决方法,因此我可以模仿路由器在应用程序内部的工作方式,并将请求“重定向”到延迟加载的模型
最佳答案 使用哈希位置策略:
RouterModule.forRoot([...], { useHash });
为什么这样做?
在大多数Web服务器(包括IIS)中,散列前面的部分被视为服务器上实际页面的路径.但该路由实际上只存在于客户端应用程序中.深层链接将首先命中服务器,当然路由不存在,因此出现404错误.使用#position策略修复了由于服务器忽略#之后的部分,因此它从服务器角度正确解析了页面. Angular将其余部分带到正确的页面.
您需要告诉Web服务器,到SPA的深层链接是可以的.这是一个看起来很不错的指南:https://gingter.org/2017/03/20/deep-link-angular-spa-iis/