Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current route name in react-navigation?

I want the name of the current route or screen in react-navigation which I want to use inside if condition to make some changes.

like image 618
Eshant Bist Avatar asked Oct 29 '18 06:10

Eshant Bist


People also ask

How do I get the current route name in react?

Use the useLocation() hook to get the current route with React Router, e.g. const location = useLocation() . The hook returns the current location object. For example, you can access the pathname as location. pathname .

How do I get the previous route in React Native?

To detect previous path in React Router, we can set the state property to an object with the location. pathname as the value. <Link to={{ pathname: "/nextpath", state: { prevPath: location.

How do I navigate with react router?

The react-router-dom package makes it simple to create new routes. To begin, you wrap the entire application with the <BrowserRouter> tag. We do this to gain access to the browser's history object. Then you define your router links, as well as the components that will be used for each route.


1 Answers

For react-navigation v5:

import {useRoute} from '@react-navigation/native';  const route = useRoute(); console.log(route.name); 
like image 68
ppuppim Avatar answered Sep 21 '22 21:09

ppuppim