0

is it possible to render an element for all paths except one?

For example:

<Link to='/a'>A</Link>
<Link to='/b'>B</Link>
<Link to='/c'>C</Link>
...
<Link to='/noRender'>No Render</Link>
...
<Link to='/z'>Z</Link>

<Route path='all expect /noRender' render={()=> (<p>rendered element</p>)}   />

Im looking for simplest/best solution.

zyng9
  • 79
  • 1
  • 2
  • 10

1 Answers1

1

Have you tried adding the logic within the render prop?

<Link to='/a'>A</Link>
<Link to='/b'>B</Link>
<Link to='/c'>C</Link>
...
<Link to='/noRender'>No Render</Link>
...
<Link to='/z'>Z</Link>

<Route path='/' render={()=> {
  if (this.props.location.pathname === "/noRender") {
    return null;
  } else {
    return <p>rendered element</p>;
  }
}} />
zyng9
  • 79
  • 1
  • 2
  • 10
Raphael Rafatpanah
  • 19,082
  • 25
  • 92
  • 158