【发布时间】:2021-09-08 21:22:34
【问题描述】:
我需要将 Link react Router 内的 props 传递给另一个组件,但由于我不理解的接口或类型声明,我不能。我一直在四处寻找,但找不到任何与此问题有关的内容(Typescript)。
这是我的组件的代码:
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
【问题讨论】:
标签: reactjs typescript react-router