reactjs - ReactJS on Windows server: Router not working - Tries to find subdirectory instead of route
问题描述
I'm running a ReactJS project on a 2019 Windows server and I'm using BrowserRouter for subroutes, the problem is that subroutes don't work in the production version. It will try to find the subdirectory instead.
For instance website.com/login doesn't work (even though it's in the router), it goes to the subdirectory login..
When you host the project as developer, website.com:8000/login does work.
What I've tried is editing my web.config with this:
but nothing changed.
Router:
<BrowserRouter>
<Route exact path="/" component={Landing} />
<Route path="/login" component={Login} />
<Route path="/logout" component={Logout} />
<Route path="/signup" component={Signup} />
</BrowserRouter>
What could be the problem?
解决方案
In case someone is looking for the answer:
Use HashRouter instead, much easier if you're dealing with subdirectories.
推荐阅读
- reactjs - 单击输入时反应小部件组合框打开
- c# - UWP RichEditBox 保存时自动向 rtf 添加新行
- html - 如何编辑 WordPress v4.9.5 页面的 html 代码
- caching - Elixir:Nebulex(缓存库)错误
- c++ - 无法将文件添加到 .zip 文件
- css - 在运行时更改 SASS 或 LESS 变量值
- vue.js - 我的 Vuetify Switch 没有改变他的值?
- python - pandas 函数返回多个值错误 - TypeError: unhashable type: 'list'
- php - 如何在视图中解释从数据库中获取的一些 html?
- json - 如何在 Eclipse 中进行 json 模式验证