ng2-pdfjs-viewer – 错误:无法匹配任何路由

huangapple go评论91阅读模式
英文:

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

  1. 在 node_modules 文件夹中找到 ng2-pdfjs-viewer 文件夹;
  2. 将 pdfjs 复制到项目中的 assets 文件夹中;
  3. 重新启动。

我的环境: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.

  1. Find the ng2-pdfjs-viewer folder in the node_modules folder;
  2. Copy the pdfjs to the assets folder in the project
  3. Restart

My environment: angular5.2.10 + ionic5.4.13 + ng2-pdfjs-viewer (latest version as of March 12, 2020)

huangapple
  • 本文由 发表于 2020年1月6日 22:15:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/59613655.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定