Skip to content

Multiple activeRouteHandlers #427

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

Closed
OscarGodson opened this issue Oct 26, 2014 · 3 comments
Closed

Multiple activeRouteHandlers #427

OscarGodson opened this issue Oct 26, 2014 · 3 comments

Comments

@OscarGodson
Copy link

I have a mobile UI where you have a header, the "app content" thats a fixed height the size of the window with overflow auto, and then on some pages a big submit button. Sort of like this UI
simple-2_0-goal-date cream-a203862a11d02556 png 1500x2500 2014-10-26 12-56-43

The HTML is sort of like:

<div class="wrapper">
  <div class="header"></div>
  <div class="app-content"></div>
  <div class="big-button"></div> <!-- on some pages, and sometimes 2 buttons -->
</div>

To achieve this design I just made .wrapper display:flex in a column. That works great. The only problem is that the app-content is where I'm putting <this.props.activeRouteHandler/> which means there's no clean way to to get the big-button to show up or hide based on the route. Is there anyway I can setup multiple <this.props.activeRouteHandler/> so it'd look sort of like:

<div class="wrapper">
  <div class="header"></div>
  <div class="app-content"><this.props.activeRouteHandler /></div>
  <div class="big-button"><this.props.activeRouteHandler2 /></div> <!-- on some pages, and sometimes 2 buttons -->
</div>

Or, do you have other suggestions on how to handle this?

@tcoopman
Copy link

The best way to do this at the moment is to pass a extra handler as a prop in your routes I believe.
Something like this:

<Routes location="history">
      <Route path="/" handler={MainSection}>
        <Route name="new" path="new" handler={handler} extraHandler={activeHandler2} />
      </Route>
</Routes>

You have to extra the second handler yourself but this works fine:

var routeHandler = this.props.activeRouteHandler();
var activeRouteHanlder2 = routeHandler.props.extraHandler;

@haohcraft
Copy link

@tcoopman Just curious. How three handlers? Besides "extraHandler", what attributes can I use? Could you please guide me to the related code base. Thanks

@ryanflorence
Copy link
Member

Look at the sidebar example to see how the parent handler can introspect the active route handler and then branch its view logic on it:

https://github.com/rackt/react-router/blob/master/examples/sidebar/app.js#L81-L84

You can mixin ActiveState and ask for all sorts of things like the active params, or even the full active route tree and walk that to decide what you want to render and where. I would not add handlers to your route config, I would branch in your handler and display different components there.

ActiveState docs

@lock lock bot locked as resolved and limited conversation to collaborators Jan 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants