【发布时间】:2021-03-19 19:16:44
【问题描述】:
我正在使用 React 和 Ionic 构建一个展示房地产的网站。
我的 App.tsx
中有此路由<IonApp>
<IonReactRouter>
<Nav />
<IonRouterOutlet id="first">
<Route exact path="/" component={Home} />
<Route exact path="/all-properties" component={Properties} />
<Route exact path="/property/:id" component={Property} />
</IonRouterOutlet>
</IonReactRouter>
</IonApp>
我链接到我网站中的单个 "/property/:id" 页面,如下所示:
<Link to={"/property/" + variableId}> ... </Link>
现在在我的"/property/:id" 页面上,我可以像这样从 URL 访问 id:
useIonViewDidEnter(() => {
console.log(props.match.params.id); // This works the first time
});
问题是,当我点击返回主屏幕,然后访问我的另一个 "/property/:id" 页面时,props.match.params.id 保持不变。没有更新。
可以做些什么来解决它?
【问题讨论】:
-
一些关于如何访问路线的代码会有所帮助
-
@AaronSaunders 我不确定你的意思,你能扩展一下吗?
标签: reactjs ionic-framework react-router-dom ionic-react