Vue 生产 URL 重定向在 gae 上返回 404



我有一个 vue 应用程序,我想部署到 google app engine。我已经部署了它,一切正常,但是当我手动输入 url 时,应用程序会以 404 响应。有什么方法可以设置 app.yaml 以允许从 url 重定向到 SPA?

# GAE yml setup
runtime: python27
api_version: 1
threadsafe: true
# URL handlers
handlers:
- url: /
static_files: dist/index.html
upload: dist/index.html
- url: /(.*)
static_files: dist/1
upload: dist/(.*)
- url: .*
static_files: dist/index.html
upload: dist/index.html
# GAE has a limit of 10,000 files so ignore node_modules and anything else thats not neccassary
skip_files:
- node_modules/
- .gitignore
- src/
- public/
- babel.config.js
- ^(.*/)?..*$

如何使用处理程序重定向到 SPA 上的特定页面?

下面是一个关于您要实现的目标的示例。

此特定解决方案(将所有 URL 重定向到单个 URL(分两步工作,修改app.yaml并在.py文件中添加一些源。

app.yaml中,通过添加处理程序:">App Engine 可以通过执行应用程序代码或提供随代码一起上传的静态文件(例如图像、CSS 或 JavaScript(来处理 URL。

handlers: - url: /.* script: main.py

.py文件中,通过添加"规则"进行重定向。

class AllHandler(webapp.RequestHandler): def get(self): self.redirect("http://example.com", True) application = webapp.WSGIApplication([('/.*', AllHandler)])

最新更新