我试图让我的 Header 组件在 Route 更改时呈现。我尝试在 Switch 上使用 onChange 和 onValueChange ,但都没有被调用。有没有办法在路由改变时调用函数?
<Switch>
<Route path="/posts/new" component={PostsNew}/>
<Route path="/posts/:id" component={PostsShow}/>
<Route exact path="/" component={PostsIndex}/>
</Switch>