Reactjs 反应路由器不理解路径变量?
我有一个react应用程序运行在AmazonS3存储桶中,它在这里可用:这是应用程序的主页,用户可以在搜索栏中搜索船只 应用程序在下拉菜单中生成如下链接:Reactjs 反应路由器不理解路径变量?,reactjs,amazon-s3,react-router,Reactjs,Amazon S3,React Router,我有一个react应用程序运行在AmazonS3存储桶中,它在这里可用:这是应用程序的主页,用户可以在搜索栏中搜索船只 应用程序在下拉菜单中生成如下链接: export class Routes extends React.Component { render() { return ( <div> <Route exact path={HOME_PAGE} component={Home}/>
export class Routes extends React.Component {
render() {
return (
<div>
<Route exact path={HOME_PAGE} component={Home}/>
<Route path={HOME_PAGE + "/details/:id"} component={Details}/>
<Route path={HOME_PAGE + "/form/:mode"} component={Edit}/>
<Route path={HOME_PAGE + "/form/:mode/:id"} component={Edit}/>
<Route path={HOME_PAGE + "/csvForm"} component={CsvForm}/>
</div>
);
}
}
但是,当用户单击链接时,您不会看到详细信息页面,但用户会被重定向到此页面,而不使用CSS
当地一切正常
我的路线组件如下所示:
export class Routes extends React.Component {
render() {
return (
<div>
<Route exact path={HOME_PAGE} component={Home}/>
<Route path={HOME_PAGE + "/details/:id"} component={Details}/>
<Route path={HOME_PAGE + "/form/:mode"} component={Edit}/>
<Route path={HOME_PAGE + "/form/:mode/:id"} component={Edit}/>
<Route path={HOME_PAGE + "/csvForm"} component={CsvForm}/>
</div>
);
}
}
导出类路由扩展React.Component{
render(){
返回(
);
}
}
我为主页
路径构建了一个前缀,如下所示:
export class Routes extends React.Component {
render() {
return (
<div>
<Route exact path={HOME_PAGE} component={Home}/>
<Route path={HOME_PAGE + "/details/:id"} component={Details}/>
<Route path={HOME_PAGE + "/form/:mode"} component={Edit}/>
<Route path={HOME_PAGE + "/form/:mode/:id"} component={Edit}/>
<Route path={HOME_PAGE + "/csvForm"} component={CsvForm}/>
</div>
);
}
}
导出常量主页=(环境=“开发”)?“”:“/url”
这将为开发或生产环境设置主页路径
我正在考虑另一种方法来将ship id传递到details页面,可能使用GET参数。因此,路由将类似于以下内容主页+/details?id=5c335682379b4d7a6ea454a8
但我不知道react路由器是否支持这种参数,也许有人有更好的解决方案来解决这个问题。只要在网站上玩一玩,我希望我已经提供了足够的信息来了解网站的结构。如果您使用react router v4,对于您定义的每个路由,react router都将通过三个道具:
- 匹配
- 位置
- 历史
params
(位于/:someParams
下),可以使用Match.params.someParams
访问Match
道具
如果您喜欢查询字符串,可以使用Location.search
来使用Location
道具,这是一个字符串,因此在您的情况下,它将返回?id=5c335682379b4d7a6ea454a8
。您必须使用qs
来处理字符串,以获取id
值
您可以在此处查看详细信息:
因此,在您的情况下,这将是解决方案:
在你父母身上
您是否在amazon s3设置中将
index.html
文件指定为错误页面?我不这么认为,顺便说一下,我没有访问服务器的权限。因为我只是公司的实习生。因此,部署过程是通过电子邮件将我的压缩构建文件夹发送给管理员。同时使用
标记。在/form/:mode/:id
中,它应该呈现编辑
两次。也是x2。您是否在下拉列表中使用
组件?这可能就是解决方案,我来看看。