Nested React Router doesn't update layout










2















App component with Root routes:



import React, Component from 'react';
import './App.css';
import Routes from './routes';

class App extends Component

render()
return (
<Routes/>
);



export default App;


Root routes:



import React from 'react';
import BrowserRouter as Router, Route, Switch from 'react-router-dom';

import Login from './scenes/Login/Login';
import Dashboard from './scenes/Dashboard/Dashboard';

const Routes = () => (
<Router>
<Switch>
<Route exact path="/" component=Login />
<Route path="/dashboard" component=Dashboard />
</Switch>
</Router>
);

export default Routes;


Nested component with nested routes:



import React, Component from 'react';
import logo from '../../logo.png';
import './Dashboard.css';
import Routes from './routes';
import Link, withRouter from 'react-router-dom';

class Dashboard extends Component

render()

return (
<div className="App">
<div id="map" />
<div className='sidebar'>
<img src=logo className="App-logo" alt="logo" />
<Link to= pathname: `/dashboard/profile` >
<i class="icon blue fa fa-2x fa-user mr-3 float-right"></i>
</Link>
<Link to= pathname: `/dashboard/notifications` >
<i class="icon blue fa fa-2x fa-bell mr-3 float-right"></i>
</Link>
<Link to= pathname: `/dashboard/home` >
<i class="icon blue fa fa-2x fa-home mr-3 float-right"></i>
</Link>
<Routes />


</div>
</div>
);



export default Dashboard;


Nested routes:



import React from 'react';
import BrowserRouter as Router, Route, Switch from 'react-router-dom';

import Notifications from './scenes/Notifications/Notifications';
import Home from './scenes/Home/Home';
import Profile from './scenes/Profile/Profile';

const Routes = () => (
<Router>
<Switch>
<Route path="/dashboard/home" component=Home />
<Route path="/dashboard/profile" component=Profile />
<Route path="/dashboard/notifications" component=Notifications />
</Switch>
</Router>
);

export default Routes;


So the problem is that when I click the Link ex.(/dashboard/notifications) it changes the url in the browser but doesn't update the layout but when I refresh the page it works fine and the proper components are visible. The / route and dashboard works fine.










share|improve this question






















  • Take a look at withRouter function in documentation

    – Vahagn Sargsyan
    Nov 13 '18 at 23:25











  • Isn’t it only for redux? Im not using redux here.

    – Wojciech Nowakowski
    Nov 13 '18 at 23:28















2















App component with Root routes:



import React, Component from 'react';
import './App.css';
import Routes from './routes';

class App extends Component

render()
return (
<Routes/>
);



export default App;


Root routes:



import React from 'react';
import BrowserRouter as Router, Route, Switch from 'react-router-dom';

import Login from './scenes/Login/Login';
import Dashboard from './scenes/Dashboard/Dashboard';

const Routes = () => (
<Router>
<Switch>
<Route exact path="/" component=Login />
<Route path="/dashboard" component=Dashboard />
</Switch>
</Router>
);

export default Routes;


Nested component with nested routes:



import React, Component from 'react';
import logo from '../../logo.png';
import './Dashboard.css';
import Routes from './routes';
import Link, withRouter from 'react-router-dom';

class Dashboard extends Component

render()

return (
<div className="App">
<div id="map" />
<div className='sidebar'>
<img src=logo className="App-logo" alt="logo" />
<Link to= pathname: `/dashboard/profile` >
<i class="icon blue fa fa-2x fa-user mr-3 float-right"></i>
</Link>
<Link to= pathname: `/dashboard/notifications` >
<i class="icon blue fa fa-2x fa-bell mr-3 float-right"></i>
</Link>
<Link to= pathname: `/dashboard/home` >
<i class="icon blue fa fa-2x fa-home mr-3 float-right"></i>
</Link>
<Routes />


</div>
</div>
);



export default Dashboard;


Nested routes:



import React from 'react';
import BrowserRouter as Router, Route, Switch from 'react-router-dom';

import Notifications from './scenes/Notifications/Notifications';
import Home from './scenes/Home/Home';
import Profile from './scenes/Profile/Profile';

const Routes = () => (
<Router>
<Switch>
<Route path="/dashboard/home" component=Home />
<Route path="/dashboard/profile" component=Profile />
<Route path="/dashboard/notifications" component=Notifications />
</Switch>
</Router>
);

export default Routes;


So the problem is that when I click the Link ex.(/dashboard/notifications) it changes the url in the browser but doesn't update the layout but when I refresh the page it works fine and the proper components are visible. The / route and dashboard works fine.










share|improve this question






















  • Take a look at withRouter function in documentation

    – Vahagn Sargsyan
    Nov 13 '18 at 23:25











  • Isn’t it only for redux? Im not using redux here.

    – Wojciech Nowakowski
    Nov 13 '18 at 23:28













2












2








2








App component with Root routes:



import React, Component from 'react';
import './App.css';
import Routes from './routes';

class App extends Component

render()
return (
<Routes/>
);



export default App;


Root routes:



import React from 'react';
import BrowserRouter as Router, Route, Switch from 'react-router-dom';

import Login from './scenes/Login/Login';
import Dashboard from './scenes/Dashboard/Dashboard';

const Routes = () => (
<Router>
<Switch>
<Route exact path="/" component=Login />
<Route path="/dashboard" component=Dashboard />
</Switch>
</Router>
);

export default Routes;


Nested component with nested routes:



import React, Component from 'react';
import logo from '../../logo.png';
import './Dashboard.css';
import Routes from './routes';
import Link, withRouter from 'react-router-dom';

class Dashboard extends Component

render()

return (
<div className="App">
<div id="map" />
<div className='sidebar'>
<img src=logo className="App-logo" alt="logo" />
<Link to= pathname: `/dashboard/profile` >
<i class="icon blue fa fa-2x fa-user mr-3 float-right"></i>
</Link>
<Link to= pathname: `/dashboard/notifications` >
<i class="icon blue fa fa-2x fa-bell mr-3 float-right"></i>
</Link>
<Link to= pathname: `/dashboard/home` >
<i class="icon blue fa fa-2x fa-home mr-3 float-right"></i>
</Link>
<Routes />


</div>
</div>
);



export default Dashboard;


Nested routes:



import React from 'react';
import BrowserRouter as Router, Route, Switch from 'react-router-dom';

import Notifications from './scenes/Notifications/Notifications';
import Home from './scenes/Home/Home';
import Profile from './scenes/Profile/Profile';

const Routes = () => (
<Router>
<Switch>
<Route path="/dashboard/home" component=Home />
<Route path="/dashboard/profile" component=Profile />
<Route path="/dashboard/notifications" component=Notifications />
</Switch>
</Router>
);

export default Routes;


So the problem is that when I click the Link ex.(/dashboard/notifications) it changes the url in the browser but doesn't update the layout but when I refresh the page it works fine and the proper components are visible. The / route and dashboard works fine.










share|improve this question














App component with Root routes:



import React, Component from 'react';
import './App.css';
import Routes from './routes';

class App extends Component

render()
return (
<Routes/>
);



export default App;


Root routes:



import React from 'react';
import BrowserRouter as Router, Route, Switch from 'react-router-dom';

import Login from './scenes/Login/Login';
import Dashboard from './scenes/Dashboard/Dashboard';

const Routes = () => (
<Router>
<Switch>
<Route exact path="/" component=Login />
<Route path="/dashboard" component=Dashboard />
</Switch>
</Router>
);

export default Routes;


Nested component with nested routes:



import React, Component from 'react';
import logo from '../../logo.png';
import './Dashboard.css';
import Routes from './routes';
import Link, withRouter from 'react-router-dom';

class Dashboard extends Component

render()

return (
<div className="App">
<div id="map" />
<div className='sidebar'>
<img src=logo className="App-logo" alt="logo" />
<Link to= pathname: `/dashboard/profile` >
<i class="icon blue fa fa-2x fa-user mr-3 float-right"></i>
</Link>
<Link to= pathname: `/dashboard/notifications` >
<i class="icon blue fa fa-2x fa-bell mr-3 float-right"></i>
</Link>
<Link to= pathname: `/dashboard/home` >
<i class="icon blue fa fa-2x fa-home mr-3 float-right"></i>
</Link>
<Routes />


</div>
</div>
);



export default Dashboard;


Nested routes:



import React from 'react';
import BrowserRouter as Router, Route, Switch from 'react-router-dom';

import Notifications from './scenes/Notifications/Notifications';
import Home from './scenes/Home/Home';
import Profile from './scenes/Profile/Profile';

const Routes = () => (
<Router>
<Switch>
<Route path="/dashboard/home" component=Home />
<Route path="/dashboard/profile" component=Profile />
<Route path="/dashboard/notifications" component=Notifications />
</Switch>
</Router>
);

export default Routes;


So the problem is that when I click the Link ex.(/dashboard/notifications) it changes the url in the browser but doesn't update the layout but when I refresh the page it works fine and the proper components are visible. The / route and dashboard works fine.







reactjs routes nested router






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 23:19









Wojciech NowakowskiWojciech Nowakowski

233




233












  • Take a look at withRouter function in documentation

    – Vahagn Sargsyan
    Nov 13 '18 at 23:25











  • Isn’t it only for redux? Im not using redux here.

    – Wojciech Nowakowski
    Nov 13 '18 at 23:28

















  • Take a look at withRouter function in documentation

    – Vahagn Sargsyan
    Nov 13 '18 at 23:25











  • Isn’t it only for redux? Im not using redux here.

    – Wojciech Nowakowski
    Nov 13 '18 at 23:28
















Take a look at withRouter function in documentation

– Vahagn Sargsyan
Nov 13 '18 at 23:25





Take a look at withRouter function in documentation

– Vahagn Sargsyan
Nov 13 '18 at 23:25













Isn’t it only for redux? Im not using redux here.

– Wojciech Nowakowski
Nov 13 '18 at 23:28





Isn’t it only for redux? Im not using redux here.

– Wojciech Nowakowski
Nov 13 '18 at 23:28












1 Answer
1






active

oldest

votes


















0














Try to use NavLink tag instead of Link and BrowserRouter instead of Router , import it from "react-router-dom"






share|improve this answer

























  • Still doesnt work :(

    – Wojciech Nowakowski
    Nov 13 '18 at 23:44











  • I have edited my response, and also try to change pathname with to="/.." inside the NavLik , this is how react router v4 work

    – G. Adnane
    Nov 13 '18 at 23:47












  • Still doesnt work :(

    – Wojciech Nowakowski
    Nov 13 '18 at 23:51











  • And the problem could not be because your are referencing to the same stateless functional components Routes, see your imports, you are using only one of 2 declared ! I think this is your problem, you are importing the same one (this first) in your two components

    – G. Adnane
    Nov 13 '18 at 23:57












  • Would you explain more what exactly should i do please?

    – Wojciech Nowakowski
    Nov 14 '18 at 0:02










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290928%2fnested-react-router-doesnt-update-layout%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Try to use NavLink tag instead of Link and BrowserRouter instead of Router , import it from "react-router-dom"






share|improve this answer

























  • Still doesnt work :(

    – Wojciech Nowakowski
    Nov 13 '18 at 23:44











  • I have edited my response, and also try to change pathname with to="/.." inside the NavLik , this is how react router v4 work

    – G. Adnane
    Nov 13 '18 at 23:47












  • Still doesnt work :(

    – Wojciech Nowakowski
    Nov 13 '18 at 23:51











  • And the problem could not be because your are referencing to the same stateless functional components Routes, see your imports, you are using only one of 2 declared ! I think this is your problem, you are importing the same one (this first) in your two components

    – G. Adnane
    Nov 13 '18 at 23:57












  • Would you explain more what exactly should i do please?

    – Wojciech Nowakowski
    Nov 14 '18 at 0:02















0














Try to use NavLink tag instead of Link and BrowserRouter instead of Router , import it from "react-router-dom"






share|improve this answer

























  • Still doesnt work :(

    – Wojciech Nowakowski
    Nov 13 '18 at 23:44











  • I have edited my response, and also try to change pathname with to="/.." inside the NavLik , this is how react router v4 work

    – G. Adnane
    Nov 13 '18 at 23:47












  • Still doesnt work :(

    – Wojciech Nowakowski
    Nov 13 '18 at 23:51











  • And the problem could not be because your are referencing to the same stateless functional components Routes, see your imports, you are using only one of 2 declared ! I think this is your problem, you are importing the same one (this first) in your two components

    – G. Adnane
    Nov 13 '18 at 23:57












  • Would you explain more what exactly should i do please?

    – Wojciech Nowakowski
    Nov 14 '18 at 0:02













0












0








0







Try to use NavLink tag instead of Link and BrowserRouter instead of Router , import it from "react-router-dom"






share|improve this answer















Try to use NavLink tag instead of Link and BrowserRouter instead of Router , import it from "react-router-dom"







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 23:39

























answered Nov 13 '18 at 23:34









G. AdnaneG. Adnane

8418




8418












  • Still doesnt work :(

    – Wojciech Nowakowski
    Nov 13 '18 at 23:44











  • I have edited my response, and also try to change pathname with to="/.." inside the NavLik , this is how react router v4 work

    – G. Adnane
    Nov 13 '18 at 23:47












  • Still doesnt work :(

    – Wojciech Nowakowski
    Nov 13 '18 at 23:51











  • And the problem could not be because your are referencing to the same stateless functional components Routes, see your imports, you are using only one of 2 declared ! I think this is your problem, you are importing the same one (this first) in your two components

    – G. Adnane
    Nov 13 '18 at 23:57












  • Would you explain more what exactly should i do please?

    – Wojciech Nowakowski
    Nov 14 '18 at 0:02

















  • Still doesnt work :(

    – Wojciech Nowakowski
    Nov 13 '18 at 23:44











  • I have edited my response, and also try to change pathname with to="/.." inside the NavLik , this is how react router v4 work

    – G. Adnane
    Nov 13 '18 at 23:47












  • Still doesnt work :(

    – Wojciech Nowakowski
    Nov 13 '18 at 23:51











  • And the problem could not be because your are referencing to the same stateless functional components Routes, see your imports, you are using only one of 2 declared ! I think this is your problem, you are importing the same one (this first) in your two components

    – G. Adnane
    Nov 13 '18 at 23:57












  • Would you explain more what exactly should i do please?

    – Wojciech Nowakowski
    Nov 14 '18 at 0:02
















Still doesnt work :(

– Wojciech Nowakowski
Nov 13 '18 at 23:44





Still doesnt work :(

– Wojciech Nowakowski
Nov 13 '18 at 23:44













I have edited my response, and also try to change pathname with to="/.." inside the NavLik , this is how react router v4 work

– G. Adnane
Nov 13 '18 at 23:47






I have edited my response, and also try to change pathname with to="/.." inside the NavLik , this is how react router v4 work

– G. Adnane
Nov 13 '18 at 23:47














Still doesnt work :(

– Wojciech Nowakowski
Nov 13 '18 at 23:51





Still doesnt work :(

– Wojciech Nowakowski
Nov 13 '18 at 23:51













And the problem could not be because your are referencing to the same stateless functional components Routes, see your imports, you are using only one of 2 declared ! I think this is your problem, you are importing the same one (this first) in your two components

– G. Adnane
Nov 13 '18 at 23:57






And the problem could not be because your are referencing to the same stateless functional components Routes, see your imports, you are using only one of 2 declared ! I think this is your problem, you are importing the same one (this first) in your two components

– G. Adnane
Nov 13 '18 at 23:57














Would you explain more what exactly should i do please?

– Wojciech Nowakowski
Nov 14 '18 at 0:02





Would you explain more what exactly should i do please?

– Wojciech Nowakowski
Nov 14 '18 at 0:02

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290928%2fnested-react-router-doesnt-update-layout%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto