-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Support <Redirect> in <Switch> #4546
Conversation
* `<Redirect>` already worked because it doesn't have a `path` and it gets rendered :) * Add `from` as an alias for `path` in `matchPath` so you can write `<Redirect from="/old" to="/new"/>` Fixes remix-run#4541
@@ -30,7 +30,8 @@ const matchPath = (pathname, options = {}) => { | |||
if (typeof options === 'string') | |||
options = { path: options } | |||
|
|||
const { path, exact = false, strict = false } = options | |||
const { exact = false, strict = false } = options | |||
const path = options.path || options.from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow, that wasn't a huge change 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems out of place to me. The components define this API (from/to/path) not matchPath
. Then this opens up weird stuff like <Route from/>
doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this whole API is a little weird to me. What does <Redirect from="..." to="...">
mean outside of a <Switch>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fewer questions with this:
const RedirectFrom = ({ from, to }) => (
<Route path={from} render={() => <Redirect to={to}/>}/>
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then this opens up weird stuff like doesn't it?
Who cares? It's an implementation detail. It's private API, we don't document it, and if anyone does any thing like <Route from>
, we don't support it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is <Redirect from to/>
intended to do outside of <Switch/>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing. I guess we could create a new component for the use case of <Redirect>
inside a <Switch>
, but we could also just tell people "don't do that".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine. <Switch>
is kind of magical anyway. It reads the data of its children
and decides what to do based on their props. We can pretty easily say <Redirect from>
is only supported inside a <Switch>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could also just hang out and wait for that from
path to match and redirect when it does ... hmm...
Thanks, @wmertens! |
<Redirect>
already worked because it doesn't have apath
and it gets rendered :)from
as an alias forpath
inmatchPath
so you can write<Redirect from="/old" to="/new"/>
Fixes #4541