Nested React Router doesn't update layout
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
add a comment |
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
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
add a comment |
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
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
reactjs routes nested router
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
Try to use NavLink tag instead of Link and BrowserRouter instead of Router , import it from "react-router-dom"
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
|
show 2 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Try to use NavLink tag instead of Link and BrowserRouter instead of Router , import it from "react-router-dom"
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
|
show 2 more comments
Try to use NavLink tag instead of Link and BrowserRouter instead of Router , import it from "react-router-dom"
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
|
show 2 more comments
Try to use NavLink tag instead of Link and BrowserRouter instead of Router , import it from "react-router-dom"
Try to use NavLink tag instead of Link and BrowserRouter instead of Router , import it from "react-router-dom"
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
|
show 2 more comments
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
|
show 2 more comments
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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