我正在使用React和Redux开发一个Web应用程序,当我开始我的项目时,我得到了这个:
Line 13: Unexpected use of 'location' no-restricted-globals
Search for the keywords to learn more about each error.
我搜索了很多有关如何解决它的方法,但是找不到任何答案对我有帮助,所以我转向了堆栈溢出。
有人知道如何解决此错误吗?我感谢我能获得的所有帮助。
尝试window
在之前添加location
(即window.location
)。
这是一个简单的方法,也许不是最好的解决方案,但是它可以工作。
在出现错误的行上方,粘贴以下代码:
// eslint-disable-next-line no-restricted-globals
也许您可以尝试将位置作为道具传递到组件中。下面我使用... otherProps。这是传播操作符,是有效的,但不是必需的,如果您明确传递了道具,它只是作为占位符用于演示目的。另外,进行结构性研究以了解({location})的来源。
import React from 'react';
import withRouter from 'react-router-dom';
const MyComponent = ({ location, ...otherProps }) => (whatever you want to render)
export withRouter(MyComponent);
对我来说,我在历史记录和位置方面遇到了问题...作为在历史记录和位置之前使用窗口的可接受答案(即window.history和window.location解决了我的问题)
/* eslint no-restricted-globals:0 */
是另一种替代方法
本文地址:http://javascript.askforanswer.com/meiyoushouxiandequanjubianliang.html
文章标签:eslint , javascript , react-router , reactjs
版权声明:本文为原创文章,版权归 javascript 所有,欢迎分享本文,转载请保留出处!
文章标签:eslint , javascript , react-router , reactjs
版权声明:本文为原创文章,版权归 javascript 所有,欢迎分享本文,转载请保留出处!
评论已关闭!