Reactjs react router v4中棘手的嵌套match.url
我想要一个在每个路由上呈现的组件,并且有子组件(例如,标题) 通过在路线中省略Reactjs react router v4中棘手的嵌套match.url,reactjs,react-router-v4,Reactjs,React Router V4,我想要一个在每个路由上呈现的组件,并且有子组件(例如,标题) 通过在路线中省略exact,我可以实现这一点 render( <Router> <Route path="/" component={App}/> </Router>, document.getElementById('app') ); 我不确定我是否正确地理解了你。我认为您应该使用path而不是url const App = ({match}) => (
exact
,我可以实现这一点
render(
<Router>
<Route path="/" component={App}/>
</Router>,
document.getElementById('app')
);
我不确定我是否正确地理解了你。我认为您应该使用
path
而不是url
const App = ({match}) => (
<Switch>
<Route path={`${match.path}/login`} component={LoginForm}/>
<Route path={`${match.path}/panel`} component={ControlPanel}/>
</Switch>
);
const-App=({match})=>(
);
我使用ver3,但我设置路由器的方式应适用于您的情况。如果要在每条管线上渲染组件,则不需要提供路径。这样做:在NavPanel内部,您将嵌套组件称为props.children。这样,所有路由器逻辑都可以放在一个地方。如果你需要的话,我可以给你一个更完整的答案。谢谢!这解决了我的问题,但没有回答我的问题:)我不太明白问题是什么。你是说使用path={${match.url}login
}等同于path=“/login”,但后者不起作用吗?差不多。Is不起作用,但嵌套时不起作用。
<Route path="/login" component={LoginForm}/>
const App = ({match}) => (
<Switch>
<Route path={`${match.path}/login`} component={LoginForm}/>
<Route path={`${match.path}/panel`} component={ControlPanel}/>
</Switch>
);