reactjs - 除了 Spotify 登录重定向路径“在服务器上找不到”之外,生产 React 应用程序正常运行
问题描述
生产 ReactJS 应用程序,使用 Google App Engine集成 Spotify Web Api ( https://developer.spotify.com/documentation/web-api/reference-beta/ ): https ://widget-dashboard-app.appspot.com/
所有路由 ( /settings
, /about
, /contact
) 都按预期工作,但是当用户尝试登录 Spotify 时,重定向路径/settings/#access_token=[BIG-LONG-TOKEN]&token_type=Bearer&expires_in=3600
会通过 GAE 导致此错误:
Error: Not Found
The requested URL /settings/ was not found on this server.
我的第一个想法是我的app.yaml
文件中有问题:
# [START runtime]
runtime: python27
api_version: 1
threadsafe: true
# [END runtime]
# [START handlers]
handlers:
- url: /
static_files: build/index.html
upload: build/index.html
- url: /
static_dir: build
- url: /.*
static_files: build/static/\1
upload: build/static/.*
- url: /settings/.*
static_files: build/static/\1
upload: build/static/.*
# [END handlers]
我已经搜索了两个星期的互联网搜索可能是什么问题。我都读过了。这。文档。
实际结果应该是:用户通过 Spotify 的 Web API 登录,并被重定向回https://widget-dashboard-app.appspot.com/settings/#access_token=[BIG-LONG-TOKEN]&token_type=Bearer&expires_in=3600
,他们的浏览器将在几秒钟内开始播放音乐。这在开发中有效。
解决方案
由于它是一个 SPA,您的路由由应用程序处理,因此您需要一条包罗万象的路由,该路由位于您的 main index.html
. 所以看起来你的通配符规则应该是这样的:
url: /.*
static_files: build/index.html
upload: build/index.html
/settings/
我认为你不需要那个
推荐阅读
- laravel - 对 laravel 的急切加载/修改器/访问器进行澄清
- css - css如何将一个标题单元格合并到一个单元格中
- c++ - C++文件io多行
- sql - 仅通过 SQL 显示在 DBGrid 中的 TCheckListBox 中选择的字段
- vaadin - 在 Tomcat 容器上运行时,聚合物资源 URL 在“上下文”下不起作用
- javascript - 使用javascript/jquery根据另一个选择的值显示/隐藏选择选项?
- html - 禁用时阻止锚点像超链接一样
- java - 如何以正确的顺序销毁 bean(使用会话和单例范围)?
- vue.js - 检查对象是否存在而不抛出错误
- sql - Redshift 数值精度截断