首页 > 解决方案 > 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:

enter image description here

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?

标签: reactjsurldirectoryreact-routerwindows-server-2019

解决方案


In case someone is looking for the answer:

Use HashRouter instead, much easier if you're dealing with subdirectories.


推荐阅读