-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Allow partial declaration of routes #193
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
+1 As my initial stab at #190 showed I originally assumed that I could build up a component that only housed routes. I'd much rather see something like:
|
Yes that would be even nicer. |
Its just JSX, return an array: var someRoutes = function() {
return [<Route/>, <Route/>];
} |
Cool, didn't know about that trick! Thank you. Skickat från min Windows Phone Från: Ryan Florence Its just JSX, return an array: var someRoutes = function() {
return [<Route/>, <Route/>];
} Reply to this email directly or view it on GitHub: |
I can't get this to work, perhaps I am missing something? when packing the routes in an array the router throws an exception here:
because route is an array. This is the code:
Either the findMatches could unpack to route component or I guess it would be possible (but not so nice) to write some unpacking code on someRoutes before inserting it into Am I missing something? |
The problem there is that although JSX would properly transform If you changed it to |
I tried that, and I get the error |
Ah, I scrolled down to far and didn't see the beginning of your question. Sorry about that. |
The way I'm currently doing it is:
Have you tried removing the function wrapper and just assigning an array. Something like:
|
Yes, that doesn't work either unfortunately.. (the same error message as above)
|
/** @jsx React.DOM */
var Router = require('react-router');
var Routes = Router.Routes
var Route = Router.Route;
var moreRoutes = function() {
return [
<Route name="foo" handler={require('../components/foo')} />,
<Route name="bar" path="/what/evz" handler={require('../components/bar')} />,
<Route name="index" path="/" handler={require('../components/index')} />
]
}
module.exports = (
<Routes>
<Route location="history" handler={require('../components/app')}>
{moreRoutes()}
</Route>
</Routes>
); Works in the |
Aha! So I tried your example @rpflorence and ofcourse it worked. I dig some fast digging and the problem is when you combine "packaged" routes and "local", like this:
Which I guess doesn't let react unpack the array because the children is now a sort of nested array. The solution is simply to not mix an array together with a lone And just to clear things up, it doesn't matter if it is a function or a array. |
Perhaps issuing a warning/error if the RouteComponent detects one of it's children to be an array, I can't be the only newcomer to run into this invisible wall, no? 👊 |
This is all just JSX, isn't it? Is the router getting in the way? On Wed, Aug 13, 2014 at 8:21 AM, Anders Åberg [email protected]
|
Actually react seems to handle this differently (??) Because this renders fine:
|
I don't mean to be a grump, but I don't see myself spending any time On Wed, Aug 13, 2014 at 8:41 AM, Anders Åberg [email protected]
|
No problem @rpflorence, sorry for being all over you in the /issues. I will happily create a PR.Thanks for all your time and help tracking this down, @rpflorence and @mtscout6 |
@rpflorence I understand your reluctance to fix this bug yourself, but may I suggest that the issue remain open or open a new issue. It may even make sense to rename it to more adequately reflect this bug. This is now a known issue that should get resolved at some point, and again I'm not saying that you have to do so. My main motivation for this would be that first it is not forgotten about. Second so that follow on users that also have this problem would see that it is already a known issue. |
woops, meant to reopen! thanks. |
This sounds like something that should be handled by @spicyj Can you confirm/deny? |
@mjackson I did an The problem is visible first in |
@abergs Ah, thank you. Sounds like that's the right place to fix the bug. |
Just to clarify, the only reason I'm not using |
Oh, didn't see that you did work as well @mjackson. I did a small change to allow nested arrays of routes, my examples worked good with it. Seems like you did that also, as well as some more work with Perhaps we did similar work? :) |
Very useful for when you want to split your routes into different sections:
Currently, the above solution works, but only as long as you only have one
<Route>
with nested child routes within your required Routesmodules (e.g.ContactsRoutes
).It doesn't work if I have multiple routes inside of ContactsRoutes, which are not nested, because of JSX not allowing multiple adjacent components.
My suggestion is to reuse
<Routes>
as a container (with no additional behavior).The text was updated successfully, but these errors were encountered: