Search code examples
javascriptreactjsreact-router-redux

React Router Redux always show first route


React router redux always show the first route. No matter which url i entered, it will render the first route.

Index.js file

<ConnectedRouter history={history}>
   <App />
</ConnectedRouter>

App.js file

export default function App() {
      return (
            <Switch>
              <Route to="/" component={Dashboard} key={1} />;         
              <Route to="/icons" component={Icons} key={2} />;         
           </Switch>
      );
    }

Solution

  • just add exact={true} to Route, default exact is set to false, just take a look here.

    <Route exact path="/" component={Dashboard} key={1} />;