How to pass props in url in react js?
P粉138711794
P粉138711794 2024-04-01 16:03:49
0
1
416

I want to know how to send the correct format of props in url in React js.

Suppose my prop name is "isOpen" and its type is Boolean.

My URL is http://localhost:3000/Home.

Now I also want to send my props through this URL. How to do it?

I have tried something like http://localhost:3000/Home/isOpen/false but it throws this error in the console.

Rejecting execution of script from 'http://localhost:3000/Home/bundle.dev.js' because its MIME type ('text/html') is not executable and strict MIME type checking is enabled.

How do i do this?

P粉138711794
P粉138711794

reply all(1)
P粉446800329

You can use a query string in the URL, in your case it should look like this:

http://localhost:3000/Home/?isOpen=false

And use the URLSearchParams and useLocation hooks to read from the URL isOpen:

const location = useLocation();
const isOpen = new URLSearchParams(location.search).get("isOpen");
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!