[英]React Nested Routing with React Bootstrap Tabs
I wanted to add routing to my gallery.我想将路由添加到我的画廊。 I am using Bootstrap Tabs on my page, and each tab has a different Carousel for a different category of pictures.
我在我的页面上使用 Bootstrap 选项卡,每个选项卡都有一个不同的 Carousel 用于不同类别的图片。 I want to add routing so that the user doesn't download all the pictures but only the part he has selected.
我想添加路由,这样用户就不会下载所有图片,而只会下载他选择的部分。
So I am using the approach with Tab.Container, Tab.Content, Tab.Pane.所以我正在使用 Tab.Container、Tab.Content、Tab.Pane 的方法。 When user selects each link the #category is added to the link, but my Route do not load the component, not even render a simple text.
当用户选择每个链接时,#category 被添加到链接中,但我的路由不加载组件,甚至不呈现简单文本。 I don't know what's wrong.
我不知道出了什么问题。
The SlideShows are wrapped in Tab.Pane with a proper eventKey. SlideShows 包装在 Tab.Pane 中,带有适当的 eventKey。
Gallery content code:图库内容代码:
import {Link, Switch, Route, useRouteMatch} from 'react-router-dom';
import Tabs from 'react-bootstrap/Tabs';
import Tab from 'react-bootstrap/Tab';
import SchodySlideShow from './../../components/Slideshows/SchodySlideshow';
import PlytkiSlideShow from './../../components/Slideshows/PlytkiSlideshow';
import BalkonSlideShow from './../../components/Slideshows/BalkonSlideshow';
import OtherSlideShow from './../../components/Slideshows/OtherSlideshow';
import { Nav } from 'react-bootstrap';
const Gallery = () =>{
let match = useRouteMatch();
return (
<React.Fragment>
{/*
The old version how it was done (and it worked)
<Tabs >
<Tab eventKey="Schody" title="Schody" className="tab-panel">
<SchodySlideShow />
</Tab>
<Tab eventKey="Płytki" title="Płytki" className="tab-panel">
<PlytkiSlideShow />
</Tab>
<Tab eventKey="Balkony" title="Balkony" className="tab-panel">
<BalkonSlideShow />
</Tab>
<Tab eventKey="Specjalne Zamówienia" title="Specjalne Zamówienia" className="tab-panel">
<OtherSlideShow />
</Tab>
</Tabs>
*/}
<Tab.Container defaultActiveKey="schody">
<Nav>
<Nav.Item>
<Nav.Link eventKey="schody" as={Link} to={`${match.url}#schody`}>Schody</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link eventKey="balkony" as={Link} to={`${match.url}#balkony`}>Balkony</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link eventKey="plytki" as={Link} to={`${match.url}#plytki`}>Płytki</Nav.Link>
</Nav.Item>
</Nav>
</Tab.Container>
<Tab.Content>
<Switch>
<Route path={`${match.url}#schody`} component={SchodySlideShow} />
<Route path={`${match.url}#balkony`} component={BalkonSlideShow } />
<Route path={`${match.url}#plytki`} component = {PlytkiSlideShow} />
</Switch>
</Tab.Content>
</React.Fragment>
);
}
export default Gallery;
<BrowserRouter>
<Tab.Container defaultActiveKey="">
<Nav>
<Nav.Item>
<Nav.Link eventKey="users" as={Link} to={`/workhub/Users`}>Users</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link eventKey="profiles" as={Link} to={`/workhub/Profiles`}>Profiles</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link eventKey="errorcodes" as={Link} to={`/workhub/ErrorCodes`}>Error Codes</Nav.Link>
</Nav.Item>
</Nav>
</Tab.Container>
<Tab.Content>
<Routes>
<Route path={`/workhub/Users`} element={ <Users/> } />
<Route path={`/workhub/Profiles`} element={ <Profiles/> } />
<Route path={`/workhub/ErrorCodes`} element = { <ErrorCodes/> } />
</Routes>
</Tab.Content>
</div>
</BrowserRouter>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.