React Link doesn't refresh the page
up vote
1
down vote
favorite
I have this code:
<Link to="/dashboard" style={{ color: '#A4A4A4' }}>Dashboard</Link>
As part of my app, but if i'm currently viewing the /dashboard
route, the page doesn't refresh.
Why? And how can i make it refresh?
reactjs react-router-dom
add a comment |
up vote
1
down vote
favorite
I have this code:
<Link to="/dashboard" style={{ color: '#A4A4A4' }}>Dashboard</Link>
As part of my app, but if i'm currently viewing the /dashboard
route, the page doesn't refresh.
Why? And how can i make it refresh?
reactjs react-router-dom
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have this code:
<Link to="/dashboard" style={{ color: '#A4A4A4' }}>Dashboard</Link>
As part of my app, but if i'm currently viewing the /dashboard
route, the page doesn't refresh.
Why? And how can i make it refresh?
reactjs react-router-dom
I have this code:
<Link to="/dashboard" style={{ color: '#A4A4A4' }}>Dashboard</Link>
As part of my app, but if i'm currently viewing the /dashboard
route, the page doesn't refresh.
Why? And how can i make it refresh?
reactjs react-router-dom
reactjs react-router-dom
asked Nov 21 at 21:26
Gambit2007
385523
385523
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You can try forcing a refresh, either with:
<Link to="/dashboard" onClick={this.forceUpdate} style={{ color: '#A4A4A4'}}>Dashboard</Link>
or
<Link to="/dashboard" onClick={() => window.location.refresh()} style={{ color: '#A4A4A4' }}>Dashboard</Link>
You can also add logic to the onClick method to check which page you are currently on, and to only refresh if you are on the dashboard.
Thanks! any reason why it doesn't just "go" to that link?
– Gambit2007
Nov 21 at 22:03
React components will only re-render if the state or props are updated. If you try to navigate to the page you are currently on, and there isn't a change in state or props in that component, the component will not re-render/refresh. If you update the state/props of the component, or force the page to refresh, it will refresh. And unfortunately,react-router-dom
will not refresh the page for you if you are navigating to the current page.
– Jordan Daniels
Nov 21 at 22:20
Hope that helps!
– Jordan Daniels
Nov 21 at 22:32
Yeah id does, thanks!
– Gambit2007
Nov 21 at 22:34
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can try forcing a refresh, either with:
<Link to="/dashboard" onClick={this.forceUpdate} style={{ color: '#A4A4A4'}}>Dashboard</Link>
or
<Link to="/dashboard" onClick={() => window.location.refresh()} style={{ color: '#A4A4A4' }}>Dashboard</Link>
You can also add logic to the onClick method to check which page you are currently on, and to only refresh if you are on the dashboard.
Thanks! any reason why it doesn't just "go" to that link?
– Gambit2007
Nov 21 at 22:03
React components will only re-render if the state or props are updated. If you try to navigate to the page you are currently on, and there isn't a change in state or props in that component, the component will not re-render/refresh. If you update the state/props of the component, or force the page to refresh, it will refresh. And unfortunately,react-router-dom
will not refresh the page for you if you are navigating to the current page.
– Jordan Daniels
Nov 21 at 22:20
Hope that helps!
– Jordan Daniels
Nov 21 at 22:32
Yeah id does, thanks!
– Gambit2007
Nov 21 at 22:34
add a comment |
up vote
1
down vote
accepted
You can try forcing a refresh, either with:
<Link to="/dashboard" onClick={this.forceUpdate} style={{ color: '#A4A4A4'}}>Dashboard</Link>
or
<Link to="/dashboard" onClick={() => window.location.refresh()} style={{ color: '#A4A4A4' }}>Dashboard</Link>
You can also add logic to the onClick method to check which page you are currently on, and to only refresh if you are on the dashboard.
Thanks! any reason why it doesn't just "go" to that link?
– Gambit2007
Nov 21 at 22:03
React components will only re-render if the state or props are updated. If you try to navigate to the page you are currently on, and there isn't a change in state or props in that component, the component will not re-render/refresh. If you update the state/props of the component, or force the page to refresh, it will refresh. And unfortunately,react-router-dom
will not refresh the page for you if you are navigating to the current page.
– Jordan Daniels
Nov 21 at 22:20
Hope that helps!
– Jordan Daniels
Nov 21 at 22:32
Yeah id does, thanks!
– Gambit2007
Nov 21 at 22:34
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can try forcing a refresh, either with:
<Link to="/dashboard" onClick={this.forceUpdate} style={{ color: '#A4A4A4'}}>Dashboard</Link>
or
<Link to="/dashboard" onClick={() => window.location.refresh()} style={{ color: '#A4A4A4' }}>Dashboard</Link>
You can also add logic to the onClick method to check which page you are currently on, and to only refresh if you are on the dashboard.
You can try forcing a refresh, either with:
<Link to="/dashboard" onClick={this.forceUpdate} style={{ color: '#A4A4A4'}}>Dashboard</Link>
or
<Link to="/dashboard" onClick={() => window.location.refresh()} style={{ color: '#A4A4A4' }}>Dashboard</Link>
You can also add logic to the onClick method to check which page you are currently on, and to only refresh if you are on the dashboard.
answered Nov 21 at 22:01
Jordan Daniels
27439
27439
Thanks! any reason why it doesn't just "go" to that link?
– Gambit2007
Nov 21 at 22:03
React components will only re-render if the state or props are updated. If you try to navigate to the page you are currently on, and there isn't a change in state or props in that component, the component will not re-render/refresh. If you update the state/props of the component, or force the page to refresh, it will refresh. And unfortunately,react-router-dom
will not refresh the page for you if you are navigating to the current page.
– Jordan Daniels
Nov 21 at 22:20
Hope that helps!
– Jordan Daniels
Nov 21 at 22:32
Yeah id does, thanks!
– Gambit2007
Nov 21 at 22:34
add a comment |
Thanks! any reason why it doesn't just "go" to that link?
– Gambit2007
Nov 21 at 22:03
React components will only re-render if the state or props are updated. If you try to navigate to the page you are currently on, and there isn't a change in state or props in that component, the component will not re-render/refresh. If you update the state/props of the component, or force the page to refresh, it will refresh. And unfortunately,react-router-dom
will not refresh the page for you if you are navigating to the current page.
– Jordan Daniels
Nov 21 at 22:20
Hope that helps!
– Jordan Daniels
Nov 21 at 22:32
Yeah id does, thanks!
– Gambit2007
Nov 21 at 22:34
Thanks! any reason why it doesn't just "go" to that link?
– Gambit2007
Nov 21 at 22:03
Thanks! any reason why it doesn't just "go" to that link?
– Gambit2007
Nov 21 at 22:03
React components will only re-render if the state or props are updated. If you try to navigate to the page you are currently on, and there isn't a change in state or props in that component, the component will not re-render/refresh. If you update the state/props of the component, or force the page to refresh, it will refresh. And unfortunately,
react-router-dom
will not refresh the page for you if you are navigating to the current page.– Jordan Daniels
Nov 21 at 22:20
React components will only re-render if the state or props are updated. If you try to navigate to the page you are currently on, and there isn't a change in state or props in that component, the component will not re-render/refresh. If you update the state/props of the component, or force the page to refresh, it will refresh. And unfortunately,
react-router-dom
will not refresh the page for you if you are navigating to the current page.– Jordan Daniels
Nov 21 at 22:20
Hope that helps!
– Jordan Daniels
Nov 21 at 22:32
Hope that helps!
– Jordan Daniels
Nov 21 at 22:32
Yeah id does, thanks!
– Gambit2007
Nov 21 at 22:34
Yeah id does, thanks!
– Gambit2007
Nov 21 at 22:34
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53420677%2freact-link-doesnt-refresh-the-page%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