-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Route which only redirects #139
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
Man ... |
For now you just need redirect classes for anything that redirects so they know where to go. Could at least share code with a Redirect mixin though. |
I don't see a problem with tacking the route props onto the arguments:
|
That last solution seems like the quickest solution, I like the idea of a regex path though. |
Seems like this is swinging back towards something like #67 |
@mtscout6 actually, this is quite perfect to me: var NotFound = React.createClass({
statics: {
redirects: {
'/style-guide': '/style-guide/components'
},
willTransitionTo: function(transition) {
var redirectPath = this.redirects[transition.path];
if (redirectPath)
transition.redirect(redirectPath);
}
},
render: function() {
return <h1>Not found</h1>;
}
});
React.renderComponent(
<Routes location='history'>
<Route handler={Guide}>
<Route name='style-guide' path='/style-guide' handler={Redirect} />
<Route name='components' path='/style-guide/components' handler={StyleGuideComponent} />
<Route name='icons' path='/style-guide/icons' handler={IconsComponent} />
<Route handler={NotFound}/>
</Route>
</Routes>,
document.body
); |
Nice I like that! |
Thanks! |
You know that would be a really easy mixin! |
If you'd like I can follow that up with a PR later today. |
actually, I don't think that works :\ |
yeah, because we don't have a root route handler that is guaranteed to be matched, we need a |
Which is where the regex pattern match would come in handy. |
Or are you thinking of a |
sorry, I'm a bit slow this morning, this is your solution 📦 var NotFound = React.createClass({
statics: {
redirects: {
'/style-guide': '/style-guide/components'
},
willTransitionTo: function(transition) {
var redirectPath = this.redirects[transition.path];
if (redirectPath)
transition.redirect(redirectPath);
}
},
render: function() {
return <h1>Not found</h1>;
}
});
React.renderComponent(
<Routes location='history'>
<Route handler={Guide}>
<Route name='style-guide' path='/style-guide' handler={Redirect} />
<Route name='components' path='/style-guide/components' handler={StyleGuideComponent} />
<Route name='icons' path='/style-guide/icons' handler={IconsComponent} />
</Route>
<Route path="*" handler={NotFound}/>
</Routes>,
document.body
); Note I just moved the <Routes location='history'>
<Route handler={Guide}>
<Route name='style-guide' path='/style-guide' handler={Redirect} />
<Route name='components' path='/style-guide/components' handler={StyleGuideComponent} />
<Route name='icons' path='/style-guide/icons' handler={IconsComponent} />
<Route path="*" handler={NotFound}/>
</Route>
</Routes> |
Would you be open to a mixin that does that? |
@mtscout6 would like to keep this library as slim as possible, but I'd encourage you to put it up on github and we'll link to it in the "Related Modules" section :) |
I have a route that I would like to always do a redirect to a deeper url. My attempt to do so is as follows: (Example is in cjsx, a coffeescript variation of jsx)
The problem is that you will ever be able to access the props in
willTransitionTo
since it's static. Do y'all have any suggestions?The text was updated successfully, but these errors were encountered: