javascript - 如何在同一页面上呈现仪表板组件
问题描述
我有仪表板组件,并且我有侧导航,它包含仪表板、管理公司、ContactUs、管理用户等菜单项。如果我单击仪表板,我需要在同一页面上呈现该仪表板组件,如果我单击管理公司然后管理公司组件应仅在同一页面上呈现,但如果我单击管理公司链接,它会将我带到新页面并在那里管理公司组件。这是我的路线...
/******. App.js. ******/
<GlobalProvider>
<BrowserRouter>
<Switch>
{routes.map((route,index)=>(
<Route key={index} path={route.path}
exact
render={(props)=> <route.component {...props}/>}
></Route>
))}
</Switch>
</BrowserRouter>
</GlobalProvider>
/**********. Routes.js **********/
const routes=[
{
path:"/auth/register", component: RegisterComponent, title:'Register'
},
{
path:"/", component: LoginComponent, title:'Login'
},
{
path:"/auth/sidebar", component: SidebarNav, title:'SideBar'
},
{
path:"/auth/forgotpassword", component: ForgotComponent, title:'ForgotPassword'
},
{
path:"/auth/dashboard", component:DashboardComponent, title:'DashboardComponent'
},
{
path:"/auth/manage/companies", component:ManageCompaniesComponent,
title:'ManageCompaniesComponent'
},
{
path:"/auth/contactus", component:ContactUsComponent, title:'ContactUsComponent'
},
请建议我在同一页面上呈现这些组件的更好方法..在此先感谢
解决方案
与其将 sidenav 放在像 Dashboard 这样的单独组件中,您可以将其包含在更高级别的组件中,例如 app.js,如下所示:
<Switch>
{routes.map((route,index)=>(
<Route key={index} path={route.path}
exact
render={(props)=> <route.component {...props}/>}
></Route>
))}
</Switch>
<SideBar/>
推荐阅读
- python - 我需要帮助来修改一个非常基本的循环以使用索引而不是变量名
- jquery - 无法在基础 5 中使用手风琴
- typescript - TypeScript 不能在泛型方法中推断受约束的类型?
- android - 自定义可扩展 RecyclerView 在 notifyItemRangeRemoved 和 notifyItemRangeInserted 上崩溃
- dialogflow-es - Google Actions 是否支持 Websocket?
- javascript - 无法从嵌套的异步调用返回字符串
- azure - 基于 ADLS 的 HDInsight 群集设置是否持久?
- python-3.x - 如何将默认烧瓶记录器输出更改为 json 记录处理程序
- flutter - 在 Flutter 中按下/离开时,TextField 会重新加载 FutureBuilder
- haskell - Liquid Haskell 中函数“map”的正确合约是什么?