Reactjs 反应路由器传递参数。如何?
具有以下特征:Reactjs 反应路由器传递参数。如何?,reactjs,params,react-router,Reactjs,Params,React Router,具有以下特征: const AppRoutes = ( <Route path="/" handler={Properties}> <DefaultRoute handler={PropertyList} /> <Route path="property/:propId" handler={PropertyDetail}/> <NotFoundRoute handler={NotFound} /> </Rout
const AppRoutes = (
<Route path="/" handler={Properties}>
<DefaultRoute handler={PropertyList} />
<Route path="property/:propId" handler={PropertyDetail}/>
<NotFoundRoute handler={NotFound} />
</Route>);
Router.run(AppRoutes, Router.HashLocation, (Root) => {
React.render(<Root />, document.getElementById('filter-content'));
});
常量批准=(
);
Router.run(AppRoutes,Router.HashLocation,(Root)=>{
React.render(,document.getElementById('filter-content');
});
我尝试在子组件内部构建动态链接,这里有一个测试
<Link to="/property/" params={{ propId: "123"}} ><img src={this.props.data.picture}
data-srcset="http://placehold.it/350x150" alt="" className="lazyload auto-height"
data-sizes="auto"/>
</Link>
但是点击链接时,propId没有通过,我做错了什么?为了实现这一点,您需要在链接组件的to属性中使用路由名称,否则路由器无法知道您指的是哪个路由定义,因此如何处理propId参数 首先,为路线定义一个名称
<Route name="property" path="property/:propId" handler={PropertyDetail}/>
然后在生成链接时使用名称:
<Link to="/property/:propId" params={{ propId: "123"}} >
我相信命名路由已被1.0+删除。我通过您的建议“警告:标签上的未知属性
params
。从元素中删除此属性。”。