Skip to content
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

Feature Request: Only render a route when the path doesn't match. #5928

Closed
RocketPuppy opened this issue Feb 9, 2018 · 1 comment
Closed

Comments

@RocketPuppy
Copy link

I've found that there are some cases where I want to render something on every page but one, or two. For example, something like a navigation header, or a site footer. You may want to remove those things in, for example, a checkout flow to remove distractions from the user. On the other hand, I definitely don't want to repeatedly add <NavHeader /> and <Footer /> everywhere. It would be nice if I could do something like this:

const Footer = () =>
  <Route
    path="/checkout"
    invert={true}
    render={() =>
      <div>
        Some cool footer links here.
      </div>
   } />;

#5866 is tracking work on allowing path to accept an array, which would fulfill my use cases exactly. Right now I'm working around this with a component wrapping a Route that always renders and doing some checking on the location using matchPath before rendering. E.g.

<Route
  children={(route) => {
    const anyMatch = Ramda.any(
      r =>
        !!matchPath(route.location.pathname, { path: r, exact: false, strict: false }),
      this.props.paths
    );
    if (!anyMatch) {
      return this.props.children;
    }
    return null;
  }} />
@timdorr
Copy link
Member

timdorr commented Feb 9, 2018

@timdorr timdorr closed this as completed Feb 9, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
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

2 participants