【发布时间】:2018-08-13 14:37:35
【问题描述】:
我有几个组件。我想要做的是当我渲染组件“购物车”时,我想禁用“应用程序”的渲染。
这是我的 index.js
ReactDOM.render(
<Provider store={store}>
<HashRouter>
<App>
<Switch>
<Route exact path="/" component={Home} />
<Route path="/categories" component={Categories} />
<Route path="/category/:categId" component={Products} />
<Route path="/product/:productId" component={Product} />
<Route path="/cart" component={Cart} />
</Switch>
</App>
</HashRouter>
</Provider>
, document.getElementById('root'),
);
我想每次在 App 组件中访问 url 并且每当路径等于“购物车”时我返回 null 但它对我不起作用。
【问题讨论】:
-
查看 React 官方文档中的“防止组件渲染”:[reactjs.org/docs/conditional-rendering.html]
标签: reactjs react-router react-redux