Работает нормально. Можете ли вы сопоставить ваш код с кодом ниже и сообщите мне, если ваша проблема решена.
Приложение. js
import React from "react";
import { Switch, Route, BrowserRouter as Router } from "react-router-dom";
import LandingPage from "./components/LandingPage";
function App() {
const [showRecommender, setRecommenderVisible] = React.useState(true);
return (
<Router>
<Switch>
<Route
path="/"
render={() => <LandingPage showRecommender={showRecommender} />}
/>
</Switch>
</Router>
);
}
export default App;
LandingPage. js
import React from "react";
const LandingPage = ({ showRecommender }) => {
console.log("showRecommender val from landingPage:", showRecommender);
return <div>landing page</div>;
};
export default LandingPage;
Консоль браузера
showRecommender val from landingPage: true LandingPage.js:4