简体   繁体   English

反应路由器 6.4.3 typescript - useLocation 任何类型错误

[英]react router 6.4.3 typescript - useLocation any type error

How am i to fix the this any type error?我该如何解决这个任何类型的错误?

I tried passing custom type but that didn't work我尝试传递自定义类型,但没有用

You can import Location from history.您可以从历史记录中导入位置。 So update would be like this所以更新会像这样

import { Location } from "history";
const location = useLocation<Location>();

or alternatively you can create types或者您可以创建类型

type LocationTypes = {
  pathname: string;
  state: any; //Here you can put your data type instead of any
  search: string;
  hash: string;
  key: string;
}

const location = useLocation<LocationTypes>();

I've been able to resolved it, I checked the node_module for the type and I saw it there.我已经能够解决它,我检查了 node_module 的类型,我在那里看到了它。 It is the same as the type LocationTypes @Evren suggested so I restarted my system and it works fine now, didn't know why it wasn't detected without having to restart my system它与type LocationTypes @Evren建议的类型相同,所以我重新启动了我的系统并且它现在工作正常,不知道为什么它没有被检测到而无需重新启动我的系统

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React App 抛出 React 路由器 `useLocation()` 错误 - React App throwing a react router `useLocation()` error React js:错误:useLocation()只能在a的上下文中使用<router>成分</router> - React js: Error: useLocation() may be used only in the context of a <Router> component React Router useLocation() 位置不跟随到当前页面 - React Router useLocation() location is not followed to the current page React Router 6 - useLocation 没有像我预期的那样工作 - React Router 6 - useLocation Not Working Like I Expected React Router Dom (v 6.4.3) 页面在导航后变得无响应 - React Router Dom (v 6.4.3) page becomes unresponsive after navigation 反应路由器打字稿错误 - react-router typescript error React typescript 错误:元素隐式具有“任何”类型 - React typescript error: Element implicitly has an 'any' type 未捕获的错误:useLocation() 只能在 a 的上下文中使用<router>零件</router> - Uncaught Error: useLocation() may be used only in the context of a <Router> component TypeScript 从 react-router-dom 升级版本 4 useParams () 后出现错误 类型“{}”上不存在属性“sumParams” - TypeScript error after upgrading version 4 useParams () from react-router-dom Property 'sumParams' does not exist on type '{}' 当将Suspense与React Router一起使用时,Typescript引发显式的函数返回类型错误 - Typescript throws an explicit function return type error when using Suspense with React Router
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM