英文:
ng2-pdfjs-viewer - Error: Cannot match any routes
问题
在使用ng serve
运行我的应用程序时,一切正常。但在使用ng build --prod
构建后,我收到以下错误信息:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment:
'assets/pdfjs/web/viewer.html'
Error: Cannot match any routes. URL Segment: 'assets/pdfjs/web/viewer.html'
... 在应该显示pdfviewer组件的时候发生了这个错误。我做错了什么?感谢您的帮助。
英文:
When running my application with ng serve
everything works fine. But after building it with ng build --prod
I get ...
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment:
'assets/pdfjs/web/viewer.html'
Error: Cannot match any routes. URL Segment: 'assets/pdfjs/web/viewer.html'
... at the moment the pdfviewer component should be displayed. What am I doing wrong? Thanks for your help.
答案1
得分: 4
将以下代码段添加到angular.json
中的"projects.your-project-name.architect.build.options.assets"
数组中,这实际上是"assets"
:
{
"glob": "**/*",
"input": "./node_modules/ng2-pdfjs-viewer/pdfjs",
"output": "/assets/pdfjs"
}
注意:尽管您的资源位于src
文件夹内,但路径是/assets/pdfjs
。
这将自动复制node_modules/ng2-pdfjs-viewer
中的pdfjs
文件夹。这比手动复制文件更好,因为手动复制文件可能会导致包更新时的版本不一致。
英文:
Add below snippet to
"projects.your-project-name.architect.build.options.assets"
array in angular.json
which is basically "assets"
{
"glob": "**/*",
"input": "./node_modules/ng2-pdfjs-viewer/pdfjs",
"output": "/assets/pdfjs"
}
NOTE: It is /assets/pdfjs
even though your assets is inside src
folder.
It will automatically copy pdfjs
folder in node_modules/ng2-pdfjs-viewer
. It is better than manually copying the files because manually copying files may cause version inconsistency on package update.
答案2
得分: 1
- 在 node_modules 文件夹中找到 ng2-pdfjs-viewer 文件夹;
- 将 pdfjs 复制到项目中的 assets 文件夹中;
- 重新启动。
我的环境:angular5.2.10 + ionic5.4.13 + ng2-pdfjs-viewer(截止到2020年3月12日的最新版本)。
英文:
I met the same problem, but I solved it. Record my solution. I hope it will help.
- Find the ng2-pdfjs-viewer folder in the node_modules folder;
- Copy the pdfjs to the assets folder in the project
- Restart
My environment: angular5.2.10 + ionic5.4.13 + ng2-pdfjs-viewer (latest version as of March 12, 2020)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论