Access path in other components
See original GitHub issueIs there any way to access/watch current path in components that are available in all routes for example header. I would like to show different links based on current path.
<Router url="{url}">
<AppHeader>
<div>
<Route path="/welcome" component="{Welcome}" />
<Route path="/login" component="{Login}" />
</div>
</Router>
<!-- AppHeader -->
<header>
<nav>
{#if currentPath != '/login' }
<Link to="/login">Login</Link>
{:else}
<Link to="/welcome">Go Back</Link>
{/if}
</nav>
</header>
Is there any preferred way to day this?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Cannot access URL path components with react-router
I'm doing this in App.js: <Route path="/discover/:query" component={Discover}/>. Then I'm trying to access the URL parameters in Discover :
Read more >How To Get Route Path Parameters In Non-Routed Angular ...
Let's call it (and other such components) the non-routed components. As it turns out, getting route path parameter in a non-routed component is...
Read more >How do I connect to a shared folder on the network?
To map a network drive, open up My Computer and select Tools, Map Network Drive. Select an available drive letter and then enter...
Read more >File path formats on Windows systems | Microsoft Learn
A standard DOS path can consist of three components: ... directory called hidden. , for example, is impossible to access in any other...
Read more >Accessing File Path Components (Recap) - Real Python
You learned about .parents that returns paths to all directories contained in the file path, and those are Path objects as well, so...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@iamfrntdv How about the following approach?
Thanks @kysonic, your solution works fine for me.
I moved my
<navbar>
component to be in scope of the<Router>
Then on the
<NavBar>
component:This way the the login button doesn’t get displayed on the
<navbar>
when the user is on the\login
route