Reactjs 带有下一个路由的reactivesearch的URL参数
有人知道如何使用Reactjs 带有下一个路由的reactivesearch的URL参数,reactjs,routing,next.js,reactivesearch,Reactjs,Routing,Next.js,Reactivesearch,有人知道如何使用next routes处理某个reactivesearch组件的URLParams的url写入吗 我的模式,比如说一些国家/地区过滤器,应该是这样的:模式:'/country/:countryname/,而不是?country=“{countryname}” 我就是这样实施的: <SingleDropdownList componentId="country" dataField="locationInformation.country.name"
next routes
处理某个reactivesearch组件的URLParams的url写入吗
我的模式,比如说一些国家/地区过滤器,应该是这样的:模式:'/country/:countryname/
,而不是?country=“{countryname}”
我就是这样实施的:
<SingleDropdownList
componentId="country"
dataField="locationInformation.country.name"
URLParams
/>
默认情况下,
urlparms
将根据查询参数设置组件的值(通过在url中查找匹配的componentId
)。但是,当使用自定义url时,默认的URLParams
将不起作用,因为它无法确定要传递给组件的值
在这种情况下,您可以使用defaultSelected
prop初始化从URL读取的组件值。如果是next routes
,您可以从query
中选择slug
,并将所需值传递给SingleDropdownList
组件:
render() {
const defaultValue = this.props.url.query.slug; // or parse it to find the required value
return (
...
<SingleDropdownList
...
defaultSelected={defaultValue}. // value from url
/>
...
);
}
<SingleDropdownList
...
onValueChange={(value) => Router.push('country', { slug: value })}
/>