My routes are like
<BrowserRouter>
<App>
<Switch>
<Route path="/:locale?" component={Home}/>
</Switch>
</App>
</BrowserRouter>
App component is
class App extends Component {
componentDidMount() {
if (this.props.match) {
console.log(this.props.match);
}
}
}
I'm getting undefined here. This only works for Home component.
I need some workaround for changing language state according to :locale for every Route. I don't want to do this manually for every route component.
exactkeyword beforepathinside yourroute?:localeis stillundefinedroute? From where you are passing the value oflocale?localhost:3000/enso thatprops.match.localeshould been. This works if put same code in all routes. I want to get it inAppthat wraps all of routes as its children.