I\'m using react-router and I want to render a menu component when the user is not in the root and not in the /login path. This is what I have so far
Use a ternary expression or short-circuit evaluation to conditionally render your component based on location.pathname, like so:
['/', '/login'].includes(location.pathname)
?
: null
}
/>
React Router's matching of path strings relies on path-to-regexp@^1.7.0.
As a result, you can instruct routes to not render for certain paths using regular expressions.
The following implementations should render given any path value, bar "/" and "/login":
// With Regex Inside String.
// With Explicit Regex.