hey guys I am learning react as I'm trying to build a website, I am facing problem with the routing using params and without. I have these routes in index.js,
This is book's home
<Route exact path="/books/bookshome" component={BookList} />
and another route to fetch individual books
<Route exact path="/books/:slug" component={SingleBook} />
The problem is whenever I open the BookList, an api request will be send by the SingleBook component and that returns an error. How can I avoid that?
I tried checking a condition in useEffect in SingleBook but it doesn't seem to work.
if(slug !=="bookshome") { fetch }
Is there a way to solve this issue or should I change the url ?
Thanks
Routes in aSwitch?Switchand the the/books/bookshomeis on top, the other shouldn't ever be hit. Could you update your code to show a bit more detail?