【发布时间】:2018-07-29 16:47:54
【问题描述】:
我在Dashboard 组件上呈现了一个左侧,旁边是当前选定页面的占位符。链接按预期更改 URL,例如dashnoard/permissions,但未呈现权限组件。但是,如果手动刷新页面,它将起作用。这是我现在正在尝试的。
class App extends Component {
render() {
return (
<Router>
<MultiThemeProvider>
<div className="App" id="siteWrap">
<AppBar title="DiversityEDU" />
<switch>
<Route exact={true} path="/" component={Home}/>
<Route exact={true} path="/login" handler={Login} component={Login}/>
<Route path="/dashboard" component={Dashboard}/>
</switch>
</div>
</MultiThemeProvider>
</Router>
);
}
}
class Dashboard extends Component {
constructor(props){
super(props);
}
render() {
return (
<Router>
<div id="dashboardWrap" style={style.dashboardWrap}>
<Sidebar links={links}/>
<div style={style.dashboardContent}>
<p>Dashboard has rendered</p>
<switch>
<Route exact={true} path="/dashboard/roles" component={Roles}/>
<Route exact={true} path="/dashboard/permissions" component={Permissions}/>
</switch>
</div>
</div>
</Router>
);
}
}
我也在这个项目中使用 Redux,但还没有直接在上面的组件中使用。
const AppContainer = connect(
mapStateToProps,
mapDispatchToProps
)(App);
【问题讨论】:
-
你在这里使用
component和render:component={Dashboard} render={() => (<Dashboard/>),使用任何一个试试。 -
我将代码更新为仅使用组件。同样的行为。
-
您在两个文件中都使用了
<Router>,在App文件中只使用一次并从所有其他文件中删除。 -
您只需要在顶层而不是嵌套路由中的路由器,也请检查此答案stackoverflow.com/questions/44356360/…
-
谢谢@MayankShukla。我也在 周围使用
,并且删除那些没有其他代码更改的问题解决了这个问题。
标签: reactjs react-router