I'm building an app with React and I'm using React routes.
I have 3 main routes:
- If the user is logged in, show Dashboard
- If the user is not logged in, show SignIn page
- If the user clicks on ForgotPassword on the SignIn page, change url and show ForgotPassword page
index.js
ReactDOM.render(
<Provider store={store}>
<BrowserRouter>
<Suspense fallback={<div>Loading...</div>}>
<div>
<Switch>
<Route path="/" component={App} />
<Route path="/login" component={Login} />
<Route path="/forgotPassword" component={ForgotPassword} />
</Switch>
</div>
</Suspense>
</BrowserRouter>
</Provider>,
document.getElementById('root')
);
App.js
{this.props.location.pathname === "/" && <Dashboard />}
<Route exact path="/users" component={Users} />
<Route path="/users/:id" component={UserPage} />
{!authenticated && <Redirect to="/login" />}
When I try to open "/", it redirects to "/login" but it doesn't render Login component.
When I replace {!authenticated && <Redirect to="/login" />} with {!authenticated && <Login>} it renders the component properly, but it doesn't change the url and it won't show the ForgotPassword page.
How do I set this properly?
<Route exact path="/" component={App} />withexactin all routes?