1.函数式组件中获取url的参数,可以从useParams()这个hook中结构出来使用。
const { id } = useParams();
2.TypeScript中的UseParams解构会报错。(Property ‘id’ does not exist on type ‘{}’.)
正解:通过如下方式指定泛型的值来告诉typescript正在使用哪些参数
const { id } = useParams<{id?: string}>();
1.函数式组件中获取url的参数,可以从useParams()这个hook中结构出来使用。
const { id } = useParams();
2.TypeScript中的UseParams解构会报错。(Property ‘id’ does not exist on type ‘{}’.)
正解:通过如下方式指定泛型的值来告诉typescript正在使用哪些参数
const { id } = useParams<{id?: string}>();