【发布时间】:2019-06-09 08:01:42
【问题描述】:
我想使用 react 路由器来导航我的应用程序。它是一个电子桌面应用程序,所以我的调试是有限的。当登录(在没有路由器的情况下运行)时,会显示带有路由器的组件,但是当显示此组件时,它不会显示确切的路由“/”。只有当我单击“链接”组件时,它才会显示。我正在使用BrowserRouter 组件。有人有想法吗?
这就是父组件的渲染方法:
render() {
return (
<Router>
<div style={styles.text}>
<AppBar title={this.state.title}/>
<Grid container className='mainGrid'>
<Grid item>
<Route exact path="/" component={Feed} />
</Grid>
</Grid>
<BottomNav/>
<Sidenav/>
</div>
</Router>
);
}
这就是BottomNav的渲染方法:
render() {
const {value} = this.state;
return (
<BottomNavigation className='BottomNav' showLabels value={value}
onChange={this.handleChange}>
<BottomNavigationAction component={Link} to="/" label="Feed" icon={<BookIcon/>}/>
<BottomNavigationAction component={Link} to="/calendar" label="Calendar" icon={<CalendarIcon/>}/>
<BottomNavigationAction component={Link} to="/mail" label="Mail" icon={<MailIcon/>}/>
<BottomNavigationAction component={Link} to="/tickets" label="Tickets" icon={<AssignmentIcon/>}/>
</BottomNavigation>)
}
这就是 Feed 组件的渲染方法:
render(){
return(
<h1>Hallo Welt (Feed)</h1>
)
}
如果您需要更多信息,请写评论。
【问题讨论】:
-
您正在使用哪个路由器组件,例如BrowserRouter, HashRouter, ...?
-
哦,对不起,我用的是BrowserRouter。我会编辑它
-
当我把
放在前面时,它可以工作,但我认为这不是一个好的解决方案 -
您确定登录重定向到“/”路由吗?因为你的路线是准确的,所以只有准确的“/”会匹配
-
不,登录不会重定向到“/”路由。如果成功,它只会从路由器渲染父组件。
标签: javascript reactjs react-router material-ui