我有一个React
前端连接到Wordpress API
并且路由在客户端定义为 React Router
。当我使用Link
时将他们引导至动态路线,他们工作得很好。但是当我直接使用浏览器地址栏按 Enter 键访问链接时,或者我刷新。我得到 p>
404 page not found
我知道这是因为正在发生对服务器的直接调用,并且没有 javascript
操纵react-router
当我们有 PHP Server
时在共享主机上执行的操作关于这一点。
考虑react-snapshot
但它不适合 API 的动态特性。请问有人可以提供解决此问题的可能方法吗?
最佳答案
看看这个:https://github.com/rafrex/spa-github-pages
这个概念可能对你有帮助。
When the GitHub Pages server gets a request for a path defined with frontend routes, e.g. example.tld/foo, it returns a custom 404.html page. The custom 404.html page contains a script that takes the current url and converts the path and query string into just a query string, and then redirects the browser to the new url with only a query string and hash fragment.
关于javascript - 具有动态路由的 react 路由器在浏览器直接链接上给出 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44733730/