Reactjs 如何获取子路由中的参数路径
我试图使用params id来获取子组件中的详细视图,但是,我得到了下一个错误 我正在阅读关于react路由器的文章,以找出问题所在,我发现我必须使用路由器。有没有另一种不用路由器就能获取参数的方法?我想像使用父组件一样使用仪表板,所以。。。也许是一种将参数传递给父组件并使用子组件中的道具的方法。。。我不知道 我的代码是: routes.jsReactjs 如何获取子路由中的参数路径,reactjs,redux,react-router,react-router-dom,routeparams,Reactjs,Redux,React Router,React Router Dom,Routeparams,我试图使用params id来获取子组件中的详细视图,但是,我得到了下一个错误 我正在阅读关于react路由器的文章,以找出问题所在,我发现我必须使用路由器。有没有另一种不用路由器就能获取参数的方法?我想像使用父组件一样使用仪表板,所以。。。也许是一种将参数传递给父组件并使用子组件中的道具的方法。。。我不知道 我的代码是: routes.js const routes = [ { path: 'app', element: <DashboardLayout />, children
const routes = [
{
path: 'app',
element: <DashboardLayout />,
children: [
{ path: 'movies', element: <MovieList /> },
{ path: 'movie/:id', element: <AccountView/>},
]
}
export default routes;
const路由=[
{
路径:“应用程序”,
元素:,
儿童:[
{路径:'movies',元素:},
{path:'movie/:id',元素:},
]
}
导出默认路径;
DetailView.js
class Detail extends React.Component {
componentDidMount() {
this.props.detail_movie(this.props.match.params.id);
}
render(){
const { classes, movie} = this.props;
return(
<Page
className={classes.root}
title="Account"
>
<Container maxWidth="lg">
<Grid
container
spacing={3}
>
<Grid
item
lg={4}
md={6}
xs={12}
>
<Profile
movie = {movie}
/>
</Grid>
<Grid
item
lg={8}
md={6}
xs={12}
>
<Details
movie = {movie}
/>
</Grid>
</Grid>
</Container>
</Page>
);
}
}
const mapStateToProps = state => ({
movie: state.movies.movie
});
export default connect(mapStateToProps, {detail_movie})(withStyles(styles)(Detail));
类详细信息扩展了React.Component{
componentDidMount(){
this.props.detail_电影(this.props.match.params.id);
}
render(){
const{classes,movie}=this.props;
返回(
);
}
}
常量mapStateToProps=状态=>({
电影:国家电影
});
导出默认连接(mapstatetops,{detail_movie})(使用样式(样式)(细节));