【发布时间】:2020-01-26 02:27:10
【问题描述】:
- 我正在尝试在我的应用中使用路由器
- 所以我使用了 react-router-dom,但我遇到了问题,
研究并找到了这个链接,但仍然没有帮助我。 Invariant failed: You should not use <Route> outside a <Router>
你能告诉我如何使用路由和链接
- 我需要重定向到另一个页面。
- 在下面提供我的代码 sn-p 和沙箱。 https://codesandbox.io/s/still-smoke-uf731
let Channel = ({ channelName, channelString, onClick, active }) => (
<div onClick={onClick} className=" col-lg-2 col-md-4 col-sm-6 ">
<div>router</div>
<Router>
<Link to={"/here"}> here</Link>
<Switch>
<Route path="/auth" />
<Route path="/" />
</Switch>
</Router>
<div
className="channel-button"
style={{
backgroundColor: active === channelString ? "orange" : ""
}}
>
<p>{channelName}</p>
</div>
</div>
);
【问题讨论】:
标签: javascript html reactjs redux router