Skip to content

Instantly share code, notes, and snippets.

@vikingmute
Created March 14, 2017 09:15
Show Gist options
  • Save vikingmute/67a2168f0a67f6b70defe4fb3cff1e5c to your computer and use it in GitHub Desktop.
Save vikingmute/67a2168f0a67f6b70defe4fb3cff1e5c to your computer and use it in GitHub Desktop.
how to render two components based on one url
// hey, I wanna show Home Component & Modal Component when url is /edit-profile
// method one
<Route path="/" component={HomePage} />
<Route path="/edit-profile" component={EditModal} />
// this will work, but when I adding another route&component like below
// when go to '/about', both Home and About will show up, I assume these are two different pages
<Route path="/" component={HomePage} />
<Route path="/about" component={AboutPage} />
<Route path="/edit-profile" component={EditModal} />
//method two
<Route path="/" exact component={HomePage} />
<Route path="/edit-profile" exact render{() =>
<HomePage><EditModal/></HomePage>
} />
// this also will work, but when go to /edit-profile link, it will cause the HomePage component re-render
// So what's the best way to handle this scenario?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment