Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 当我单击仪表板中的菜单时,React router显示空白页_Reactjs_React Router - Fatal编程技术网

Reactjs 当我单击仪表板中的菜单时,React router显示空白页

Reactjs 当我单击仪表板中的菜单时,React router显示空白页,reactjs,react-router,Reactjs,React Router,我有两个页面,在我的主页中有一个呈现登录、注册和仪表板页面的路径,在我的仪表板中有一个呈现内容的路径,如果我单击侧边栏菜单。 问题是,如果我单击侧边栏菜单来呈现内容,它会呈现空白页面 我的主页 render() { return( <Switch> <Route path ="/home" exact component={Home}/> <Route path="/login" exac

我有两个页面,在我的主页中有一个呈现登录、注册和仪表板页面的路径,在我的仪表板中有一个呈现内容的路径,如果我单击侧边栏菜单。 问题是,如果我单击侧边栏菜单来呈现内容,它会呈现空白页面

我的主页

  render() {
    return(
        <Switch>

            <Route path ="/home" exact component={Home}/>
            <Route path="/login" exact component={LoginForm}/>
            <Route path="/register/" exact component={RegisterForm}/>
            <Route path="/dashboard" component={dashboard}/>
            <Redirect exact from="/" to="/home"/>
        </Switch>
    )
  }
}
render(){
返回(
)
}
}
我的仪表盘

<div class="wrapper">
        <NavBar />
        <aside class="main-sidebar sidebar-dark-primary elevation-4">
          <SidebarMenu />
        </aside>
        <div class="content-wrapper">
            //my content
            <Route path="/dashboard/userlist" exact component={ListUser}/>
        </div>
</div>

//我的内容
我只想呈现内容而不呈现侧边栏菜单。但它会显示空白页面,就像它移回主页一样。 如果我把route path=“/dashboard/userlist”放在我的主页中,它可以工作,但他可以呈现我只想呈现内容的所有内容

我还在学习使用这个react路由器。

当你重定向到“/dashboard/userlist”时,它会通过你的switch语句,因为没有匹配项,它会重定向到hom,这意味着它会通过你的重定向组件

带上你的

 <Route path="/dashboard/userlist" exact component={ListUser}/>

最重要的

 <Route path="/dashboard" component={dashboard}/>

并且在这个上面加上“精确”

<Route path="/dashboard" exact component={dashboard}/>

所以应该是这样

<Switch>
    <Route path ="/home" exact component={Home}/>
    <Route path="/login" exact component={LoginForm}/>
    <Route path="/register/" exact component={RegisterForm}/>
    <Route path="/dashboard/userlist" exact component={ListUser}/>
    <Route path="/dashboard" exact component={dashboard}/>
    <Redirect exact from="/" to="/home"/>
</Switch>


试试这个,如果你有更多问题,请告诉我。

它可以工作,但它可以渲染所有内容。我只想渲染内容,而不渲染菜单面板