question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access to the current Route

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
salmanmcommented, Oct 10, 2015

@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 Routes

<Route path="/" component={Main}>
  <IndexRoute component={SomeComponent}/>
  <Route path="/some-other-path" component={SomeOther} />
</Route>

Then 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?

1reaction
sethmcleodcommented, May 1, 2016

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found