I use react-router-dom version ^5.1.2 and try to pass dynamic property. My root component looks like this:
export const RegisterRoutes: React.FunctionComponent<RouteComponentProps> = ({
match,
}: RouteComponentProps) => {
const root = match.url;
return (
<Switch>
<Route exact path={`${root}/success`} component={RegisterSuccess} />
<Route exact path={`${root}/success/email`} component={RegisterEmail} />
<Route exact path={`${root}/confirmation/email/:code`} component={RegisterEmailConfirmation} />
<Redirect to={root} />
</Switch>
);
};
Here is a child RegisterEmailConfirmation component:
export const RegisterEmailConfirmation: React.FunctionComponent<RouteComponentProps> = ({ match }) => {
console.log(match.params.code) // expected 'code' property from the url
return (
<SomeContent />
/>
);
I have an url from the BE with dynamic 'code' parameter, it looks like this: register/confirmation/email?code=fjds@dfF. How can I render RegisterEmailConfirmation component and read 'code' property inside? What's wrong with my code?