Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Links change URL but not rendered component #4975

Closed
cameronb23 opened this issue Apr 14, 2017 · 3 comments
Closed

Links change URL but not rendered component #4975

cameronb23 opened this issue Apr 14, 2017 · 3 comments

Comments

@cameronb23
Copy link

cameronb23 commented Apr 14, 2017

I have the bulk of my code located here if you would like to look: https://gist.github.com/cameronb23/3e8841efbd09b9cb135c5702817e5563

I have my routes and navigation set up to reflect that each should direct to a certain route. However, when I click those navigation elements, it changes the URL in my browser, but does not update anything being rendered in the DOM.

Expected Behavior

Switch to route specified and update rendered component and URL accordingly

Actual Behavior

Changes URL but not actual component that is supposed to be rendered on each route.

@cameronb23 cameronb23 changed the title Links change URL but not render Links change URL but not rendered component Apr 14, 2017
@timdorr
Copy link
Member

timdorr commented Apr 15, 2017

This guide holds the answers you seek: https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/guides/blocked-updates.md

@JarLowrey
Copy link

JarLowrey commented Nov 15, 2017

My issue was using multiple Routers, one for Link and one for Route. To fix this I wrapped the entire App in a Router, instead of individual parts.

WRONG:

App.js

render(){
  return (
	<div>
		<Header />
                <Router >
			<Switch>
				<Route exact path="/" component={Home} />
			</Switch>
                </Router>
	</div>
  );
}

Header.js

render(){
  return (<Router ><Link to="/asdf" /></Router>);
}

CORRECT:

App.js

render(){
  return (
    <Router >
	<Header />
	<Switch>
		<Route exact path="/" component={Home} />
	</Switch>
    </Router>
  );
}

Header.js

render(){
  return (<Link to="/asdf" />);
}

Edited for clarity.

@r3wt
Copy link

r3wt commented Jan 4, 2018

Just to add, for me it was because my AppLayout class was a PureComponent. switching to Component resolve matter.

@remix-run remix-run deleted a comment from robcalcroft Jan 26, 2018
@remix-run remix-run locked as resolved and limited conversation to collaborators Jan 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants