我需要将Link react Router内部的props传递给另一个组件,但由于接口或类型声明我不理解,所以无法传递。我一直在找,找不到任何关于这个问题的东西(打字稿(。
这是我的组件的代码:
const ImageGallery = () => {
interface passProps {
backUrl?: string
}
const backUrl = '/some/other/value';
return (
<Gallery>
{images.map((x, i) => (
<Link key={x} to={{ pathname: 'page', query: { backUrl } }}>
...
这是一个错误:
(property) backUrl: string
Type '{ pathname: string; query: { backUrl: string; }; }' is not assignable to type 'LocationDescriptor<unknown> | ((location: Location<unknown>) => LocationDescriptor<unknown>)'.
Object literal may only specify known properties, and 'query' does not exist in type 'LocationDescriptorObject<unknown> | ((location: Location<unknown>) => LocationDescriptor<unknown>)'.ts(2322
您可以通过state
属性向<Link>
组件添加状态。
以前在这里回答