Access to the current Route
See original GitHub issueI haven’t found a way to get access to the current route that gave rise to the route handler - i’ve hacked your code in RouteHandler like this…
createChildRouteHandler(props) {
var route = this.context.router.getRouteAtDepth(this.getRouteDepth());
if (route == null)
return null;
var childProps = assign({}, props || this.props, {
ref: REF_NAME,
params: this.context.router.getCurrentParams(),
query: this.context.router.getCurrentQuery(),
route:route
});
return React.createElement(route.handler, childProps);
}
I’m sure this isn’t the way to do it but is there a better way to get this access?
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How to get current route - angular - Stack Overflow
In the V3 (RC.3) router you can inject ActivatedRoute and access more details using its snapshot property. constructor(private route:ActivatedRoute) ...
Read more >How to get current route URL in Angular
Steps to get current route URL in Angular. 1. Import Router,NavigationEnd from angular/router and inject in the constructor. 2.
Read more >How to get the current route or URL in Angular
There are many ways by which you can get a current Route or URL in Angular. You can use the router service, location...
Read more >How to get current route in Next.js ? - GeeksforGeeks
Method 1: Using useRouter() Method: In NextJs we can easily get the value of the current route using the useRouter() function. To use...
Read more >Retrieving Current Route - Slim Framework
If you ever need to get access to the current route within your application all you have to do is call the request...
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 Free
Top 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
@ryanflorence Does
this.props.route
serve the purpose of finding the depth of current route? Because I’ve seen it to return the Main route. For e.g. if following are my RoutesThen inside Main.js, I can only see
this.props.route
as Main route even if I have navigated to/some-other-path
.Basically, how in 1.0 do we find if we’re at root route level or not? To show side menu, or back button.
Any idea?
@salmanm In v1.0 was able to find the current route pathname by using
this.props.location.pathname
. You could then check that against/
to see if you’re at the root level, or use it to run code conditionally for different routes.