2
I’m making an App, using React with typescript and React-router-dom. But I’m having a hard time working with query params on routes. My initial goal was just to receive the token and email that comes in the params query.
The token is here in the following format:
http://localhost:3000/User/ConfirmEmail/?token=asdas&[email protected]
Routes.tsx
<Router>
<Switch>
<Route exact path="/" component={Home} />
<Route
exact
path="/User/ConfirmEmail/:token"
component={ConfirmEmail}
/>
</Switch>
</Router>
confirmEmail.tsx
interface ParamTypes {
token: string;
email: string;
}
const ConfirmEmail: React.FC = () => {
const { token, email } = useParams<ParamTypes>();
useEffect(() => {
console.log(token, email);
});
return (
<>
{token}
{email}
</>
);
};
I’ve been doing research for two days, and I find very few people talking about a similar example. The most I can find are examples of the React-router-dom that is in his documentation. Thanks for your help!
Good afternoon, Thank you very much for the reply. Helped me a lot here, I will manage to evolve now with the project. I think my confusion in the documentation was to see 'URL Paramets' instead of 'Query Paramets', hahaha, I will follow the hint to put the routes as suggested. Thank you!
– Bruno D.assis
@Brunod.Ssis if it is useful to vote in answer to your question
– novic