即使包含在<route>

时间:2017-08-06 09:12:41

标签: react-router react-router-v4 react-router-dom

我正在使用react-router-dom。即使由于点击<Route>中的<NavLink>而导致位置发生变化,我的<Nav>内的孩子也无法重新渲染。 <Header>负责呈现呈现<Route>的{​​{1}}:

<Nav>呈现:

<Header>

我们看到行class Header extends PureComponent<void, void, void> { render() { return ( <div className="App-header"> <img src={logo} className="App-logo" alt="logo" /> <h2>Catchem</h2> <Route component={Nav} /> </div> ) } } ,我希望每次路径更改时都重新渲染。但事实并非如此。你能帮我理解为什么当路径改变时它不会重新渲染吗?点击<Route component={Nav} />中的<NavLink>会导致路径更改。

这是我的<Nav>

<Nav>

这是我的class Nav extends PureComponent<void, Props, void> { render() { const { location } = this.props; console.log('nav props:', this.props); return ( <div className="nav"> { PAGES.map( ({path, label}) => ( <NavLink exact className="topnav-link" activeClassName="topnav-link-selected" key={path} to={path} location={location} exact> {label} </NavLink> )) } </div> ) } }

<App>

0 个答案:

没有答案