and App.js and App.js and App.js

React-router redirect my routes in production mode

304 views Asked by At

I've got this route configuration in my React App:

index.js
    <BrowserRouter basename="/">
        <App />
    </BrowserRouter>

and

App.js
      <Switch>
        <Route path={PathConst.toLoginPage} exact>
          {user ? <Redirect to={PathConst.toHomepage} /> : <Login />}
        </Route>
        <Route exact path={PathConst.toHomePage}>
          {user ? <Dashboard /> : <Redirect to={PathConst.toLoginPage} />}
        </Route>
        <AuthRoute path={PathConst.toUserPage} Component={UserPage} exact isAuthenticated={user} requiredRoles={[UserRoles.USER_VIEW]} />
      </Switch>

I'm using react-router-dom 4.3.1;

Let's say I want to open /gui/users

In localhost:3000 it works correctly both open page using component and window.open(${path}) or writing my path directly in the browser address bar (on another tab). eg. localhost:3000/gui/users

In production mode it works correctly just with component. While if I try to write my path in the browser (on another tab) or using window.open(${path}) it automatically redirects me in my HomePage. eg. production:8000/gui/users redirects to production:8000/gui/

The backend is written with Spring, the web server is Tomcat.

I think it could be a problem with client-side routing. Any ideas how to solve it?

0

There are 0 answers