-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Multiple routers on the same page? #187
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
It's a different model: var App = React.createClass({
render: function() {
return (
<div>
<MainSidebar/>
<MainContent/>
</div>
)
}
});
var User = React.createClass({
render: function() {
return (
<div>
<UserSidebar/>
<UserContent/>
</div>
)
}
});
var routes = (
<Routes>
<Route path="/" handler={Main} />
<Route name="user" path="users/:userId" handler={User}/>
</Routes>
); |
I think it would be nice if something like this was possible: <Routes>
<Route name="main" handler={Main} />
<Route name="user" handler={{main: User, sidebar: UserSidebar}} />
</Route>
</Routes
var Main = React.createClass({
render: function() {
return (
<div>
<this.props.activeRouteHandler[sidebar] />
<this.props.activeRouteHandler[main] />
</div>
)
}
});
.... |
Interesting, these are equivalent to ember's named outlets. Maybe Sent from my iPhone
|
@rpflorence that would be nice 👍 |
Can't you already achieve the same with something like // Routes
<Routes>
<Route name="main" handler={Main}>
<Route name="user" sidebarHandler={SidebarUser} handler={User} />
</Route>
</Routes>
// Main
var Main = React.createClass({
render: function(){
var routeHandler = this.props.activeRouteHandler();
var sidebarHandler = routeHandler.props.sidebarHandler();
return <div>
{sidebarHandler}
{routeHandler}
</div>;
}
}); or is that bad practice? Also, multiple handlers would only work with routes that have no children, wouldn't they? |
It certainly gets weird, but I think it's worth exploring. A feature like this would probably kill many requests to know all the router internal data. Sent from my iPhone
|
taurose, that's actually pretty slick, can't think of gotchas at first glance. |
@taurose In your example Of course, these props are still available in |
See also how this is possible in scalajs-react: https://github.com/japgolly/scalajs-react/blob/master/extra/ROUTER2.md#nested-routes-modules |
In case anybody stumbles into this issue, looking for a way to have multiple components per route (simply put), check this sidebar example (found here). |
I accomplish this behavior using RouteHandlers. I have a dashboard with navs down the side, then when you click one, it fills in the main area with a list and a RouteHandler, when you select one, it populates the details. Think of gmail: select folder, then message from the list then it shows the message. Only one Router. You can do this already. |
I'm currently migrating an old backbone app to react. To do that I have to render react components at different places in the backbone views, so there are multiple Unless there's a way to render the Is rendering multiple routers something react-router might support in the future? |
You can do this with multiple memory history instances. |
What is ? How is it different from ? Cannot find it in the docs: https://github.com/ReactTraining/react-router/blob/master/docs/API.md |
API changes: - adds `useActionData` - actions can now return anything, redirects aren't enforced - can no longer return a string for redirects from actions since strings are valid route data - s/useRouteData/useLoaderData/ for better parity with `useActionData` since both are "route data" - `usePendingFormSubmit().data` is now a `URLSearchParams` instead of `FormBody` because it serializes better, unlikely to break any apps except for type extensions they may have created Implementation notes: - All the "pending form" stuff is no longer persisted in memory, but instead the form submit information lives on `location.state`, which simplified some code and enabled `useActionData` to even work at all. This is also why `usePendingFormSubmit().data` is a `URLSearchParams` instead of `FormData`, we needed to serialize the form data to a string (the same way the browser does) to be able to resubmit on pop events. Extra benefit is that reposts will work even across domain navigation :D - I took some shortcuts on types, need to go clean those up but I have some questions about the types on history/react-router that are related. Closes #187
Is there a way to have multiple routers on the same page, like react-router-component (http://andreypopp.viewdocs.io/react-router-component/multiple)?
Lets say I have a sidebar and a main content area on the same page, how can I have both of them to render a different react component based on the route?
The text was updated successfully, but these errors were encountered: