Being pretty new to React, I'm facing an issue with navigating between 2 components.
My app is as follows: App.js:
<div className="App">
<AuthProvider>
<ThemeProvider theme={theme}>
<CssBaseline />
<CartProvider>
<SiteHeader/>
<div>
<Routes>
{getRoutes(routes)}
<Route path="/auth" element={<AuthPage />} />
<Route path="/cart" element={<CartPage />} />
<Route path="/search_results" element={<SearchResultPage />} />
<Route exact path="/_healthz" element={<HealthPage />} />
<Route path="/orders" element={<OrderPage />} />
<Route path="/category/:id" element={<CategoryPage />} />
<Route path="/product/:id" element={<ProductPage />} />
<Route path="/recipe/:id" element={<RecipePage />} />
<Route path="/" element={<HomePage />} />
</Routes>
</div>
</CartProvider>
</ThemeProvider>
</AuthProvider>
</div>
As you can see, there is the SiteHeader component on every page. On this SiteHeader Component, I have a search field, triggering a navigate() to SearchResultPage Although the navigation itself is working (SearchResultPage is displaying), the parameters passed to navigate() are not propagated:
const search = () => {
console.log("Calling search =>" + searchTerm);
navigate("/search_results",{ state: { searchText: searchTerm }});
}
Below the code part for SearchResultPage:
export default function SearchResultPage(props) {
console.log(props);
let searchText = props.location.searchText
I don't understand why props is empty although I populated the navigate(path,state) correctly