Iâm not sure this is more related to the hook âuseMoralisQueryâ or to the hook âuseNavigateâ from react-router-dom v6, but I canât find a solution.
MainRouter.js
<BrowserRouter>
<NavBar/>
<Routes>
<Route exact path="/" element={<HomePage/>}></Route>
<Route path="item" element={<ShowItem/>}>
<Route path=":itemId" element={<ShowItem/>}>
</Route>
</Route>
</Routes>
</BrowserRouter>
The navbar includes a search bar s.t. Iâm able to search different items: âitem/1â, âitem/2â, ⌠For sake of semplicity, I replace the search bar with a button which try to redirect always to item 12
NavBar.js
return (
[...]
<button onClick={()=>navigate("/item/12")}>Click</button>
);
The ShowItem component should fetch my Moralis class marketItem matching the itemId.
ShowItem
function ShowItem(){
const match = useMatch('item/:itemId');
const { data, error, isLoading } = useMoralisQuery("marketItem", query =>
query.equalTo("tokenId", match.params.itemId))
let NFT = JSON.parse(
JSON.stringify(data, [
"tokenId",
"itemId",
"minter",
"price",
"commissioni",
"tokenURI",
"hasPvtImg"
])
)[0]
return(
<>
{
NFT ?
<>{NFT.tokenId} found</>
:
<div>{match.params.itemId} not found</div>
}
</>
);
}
If Iâm in any page but âitem/*â, the navigation works as expected. Ex. if Iâm at âhomepageâ, the button redirects to âitem/12â and the data is loaded
However, the strange behaviour happens if my current page is âitem/*â, ex. âitem/1â. In this case, if I press the button the url changes to âitem/12â but the content doesnât load: the correct content is loaded only if I manually refresh the page
Do you have any suggestion? Thanks