[SOLVED] How do I add id parameters to the url of a html page?


This Content is from Stack Overflow. Question asked by devdoesit

I want to add URL parameters to a HTML page. Can’t seem to find out how to do it using react without the use of the Link class.

I’m looking to do the following

ex: https://www.example.com/anotherpage.html/:id

id = some-sub-page


Add route definition for sub page

<Route path="/subpage/:id">
  <SubPageComponent />

Now in sub page component:

import { useParams } from 'react-router';

export default function SubPageComponent() {
  const { id } = useParams();

Also, why do you have .html in route, please read the docs of react and any routing library: https://v5.reactrouter.com/web/example/url-params

For non react router way:


This Question was asked in StackOverflow by devdoesit and Answered by Priyanshu Chauhan It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?