我打开/view
路由整个BaseLayout
时出现的问题是渲染,并且我尝试了许多其他方法仍然没有运气
import React from 'react';
import { BrowserRouter as Router, Route } from "react-router-dom";
function App() {
return (
<Router>
<Root>
<Route path="/" exact component={Home}/>
<BaseLayout>
<Route path="/dashboard" exact component={Dashboard} />
<Route path="/sa" exact component={sample} />
</BaseLayout>
<Route path="/view" exact component={Post} />
</Root>
</Router>
);
}
答案 0 :(得分:1)
如果您使用render
道具而不是component
道具,并且像上面一样使用BaseLayout
包装要渲染的组件,它应该可以工作:
import React from 'react';
import { BrowserRouter as Router, Route } from "react-router-dom";
function App() {
return (
<Router>
<Root>
<Route path="/" exact component={Home}/>
<Route path="/dashboard" exact render={() => (
<BaseLayout><Dashboard /></BaseLayout>
)} />
<Route path="/sa" exact render={() => (
<BaseLayout><sample /></BaseLayout>
)} />
<Route path="/view" exact component={Post} />
</Root>
</Router>
);
}