0
state = { 
      heading:"a"
     }
componentDidUpdate=async(prevProps,prevState)=>{
       if(prevState.heading!==this.state.heading){
         // use this.setState
       }
     }

<Route path="/" exact component={A}/>
<Route path="/b" exact component={B}/>
<Route path="/c" exact component={C}/>

I want to change heading to b and c according to the route. I don't know how to use "match" or "params" here in route

ronnie
  • 69
  • 1
  • 10

1 Answers1

0

Well, as i understand from your code, you want to do something depending on the current route.

The useLocation hook returns the current URL as an object:

import { useLocation } from 'react-router-dom'


.
.
.
const url = useLocation();
console.log(url.pathname);
.
.
.
Ahmad MOUSSA
  • 2,729
  • 19
  • 31