I created a react app that will be served from /example-path. I defined it in the package.json like this:
"homepage":"/example-path"
It has worked so far, but now I would like to add routing with react-router-dom, and it incorrectly detects /example-path as the part of the URL.
This is my code:
<Router>
<Switch>
<Route path="/product/:id" children={<DisplayProduct />} />
</Switch>
</Router>
Unfortunately react-router-dom tries to match the full URL /example-path/product/10. How is it possible to avoid that? Is it possible to access the homepage variable somehow?
I could use <Router basename="/example-path">, but in that way, this parameter is a duplicate. I would like to define it in only one place.
from How is it possible to access homepage from package.json in a react app?
No comments:
Post a Comment