-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Exclusive matching #3994
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
Comments
Also, because there is no way to define exclusivity, one has to trick the MainApp using Miss: const NoMatch = ({ location }) => (
<div>
<h2>Whoops</h2>
<p>Sorry but {location} didn’t match any pages</p>
</div>
)
const MainApp = () => (
<div>
<h2>Main App</h2>
<Match exactly pattern="/About" component={About} />
<Miss component={NoMatch} />
</div>
)
class App extends React.Component<any, any> {
render() {
return <HashRouter>
<div>
<Match pattern="/OtherApp" component={OtherApp} />
<Match pattern="/YetAnotherAppf" component={YetAnotherAppf} />
<Miss component={MainApp} />
</div>
</HashRouter>;
}
} And even in my example, the NoMatch does not work because two Miss can't be inside each other, I think. |
Here is a (fledging, incipient) proof of concept: |
@Ciantic you want |
@ryanflorence That would breaking nesting within MainApp, if there was nesting there that is different from the Matches at the app level. I have a similar example trying to get it into text. |
Let's keep @Ciantic's conversation over on #4016 @aaronshaf I'm not totally understanding what |
@ryanflorence |
gotcha, that would make things order dependent, I have something I'm still playing with that would probably meet the use-cases you've got ( |
@ryanflorence hmm, I thought exactly means basically I mean why would exactly "/" match the "/about"? That is why I think I need exclusive. |
I think something akin to 'exclusive' would solve my issue too, as I never want more than Match to apply at once. Like how routes in express stop matching after the first hit.
/terms => Terms Right now, /terms and /product/prod-id also displays the 'ProductList' component |
Is this now supported? Match was renamed Route, and MatchGroup does not exist anymore. Is exclusivity achieved some other way? |
Apologies, combing through these various docs, I found MatchGroup is renamed to "Switch" |
Always best to check the docs before commenting on issues, @Ciantic :) Please submit a PR if something's missing! Beta next week! :D |
Yes I had bookmarked the old docs ( https://react-router.now.sh/ they are not updated anymore ) was scouring those, then the README. |
"React Router lets you match in multiple places on purpose" (https://react-router.now.sh/ambiguous-matches)
For simplicity it'd be nice to have an
exclusive
property:This would simplify use of Match/Miss. It could be exclusive relative to its Match siblings.
The text was updated successfully, but these errors were encountered: