在此服务器上找不到请求的URL-使用Google Cloud进行Angular 2路由 [英] The requested URL was not found on this server - Angular 2 Routing with Google Cloud

查看:342
本文介绍了在此服务器上找不到请求的URL-使用Google Cloud进行Angular 2路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前遇到的问题是当我尝试输入特定的路线时,例如:"www.example.com/projects".然后产生:

The issue that I am currently experiencing is when I attempt to put in a specific route for example: "www.example.com/projects". This then produces:

错误:未找到

在此服务器上找不到请求的URL/projects.

Error: Not Found

The requested URL /projects was not found on this server.

注意:通过用户界面导航到该路由时不会发生这种情况,只有刷新页面或输入特定的网址时才会发生这种情况.

要提及的一件事是,我正在使用Google Cloud平台,并且首先使用angular cli设置了应用程序.

我已经看到很多事情表明必须为每条路线提供index.html,但是我找不到任何有关如何执行该操作的文档,即使那是解决该问题的正确方法.

我不确定您需要什么来帮助我解决此问题,因此我将为您提供帮助的最新信息.

Note: This does not happen when navigating to that route via UI, it only happens when refreshing the page or typing in the specific url.

One thing to mention is the I am using the google cloud platform and I set up the application first using angular cli.

I have seen multiple things stating that I have to serve the index.html for each route however I cannot find any documentation as to how to do that or even if that is the correct way to go about it.

I am not sure what all you would need to help me figure this out so I will update with what you need to assist.

我的哈希定位策略正常运行,但是我试图使路径定位策略正常运行.

I got the Hash Location Strategy working, but I am trying to get the Path Location Strategy working.

谢谢您的帮助!

推荐答案

在您的app.yaml文件中,更新处理程序的正则表达式,使其看起来像这样:

In your app.yaml file, update your handler's regular expression to look like this:

- url: /(.*\.(gif|png|jpg|css|js)(|\.map))$
  static_files: dist/\1
  upload: dist/(.*)(|\.map)

- url: /(.*)
  static_files: dist/index.html
  upload: dist/index.html

dist文件是cli的静态输出.如果您的应用使用更多文件扩展名,请在第一个处理程序中添加任何文件扩展名.

The dist file is the static output from cli. Add any file extensions in the first handler if your app uses more.

希望它能起作用

这篇关于在此服务器上找不到请求的URL-使用Google Cloud进行Angular 2路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆