[英]react-router Link highlight sibling route active
I have a route config similar to this: 我有一个与此类似的路由配置:
<Route path="/">
<Route component={Books} path="books" />
<Route component={BookDetail} path="books/:bookId" />
</Route>
Is it possible to highlight a Link
active that points to /books
when /books/:bookId
is active? 当
/books/:bookId
处于活动状态时,是否可以突出显示指向/books
的Link
活动状态?
I know this can be achieved with making /books/:bookId
a child of /books
, however I'd like to avoid this as BookDetail
actually replaces Books
completely in the view. 我知道可以通过使
/books/:bookId
作为/books
的子代来实现,但是我想避免这种情况,因为BookDetail
实际上在视图中完全替换了Books
。
My current solution is that BookDetail
is a child of Books
and Books
has a condition to render either itself when exactly its route is active or otherwise its children. 我目前的解决方案是,
BookDetail
是儿童Books
和Books
都需要渲染的条件要么本身究竟何时它的路线是主动或否则其子女。 I'd like to avoid this if possible. 如果可能的话,我想避免这种情况。
Not sure if I understand it well, but I don't have enough point to post comment. 不知道我是否了解得很好,但是我没有足够的观点发表评论。 You can pass an extra parameter to
您可以将一个额外的参数传递给
<Route path="/">
<Route component={Books} path="books" />
<Route component={BookDetail} path="books/:bookId" isDetail={true} />
</Route>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.