[英]I get this error 'TypeError: toLocation is undefined' in my react project
I wanted to show sign In button on top of the page using NavLink in react-router-dom
this is the code causing the problem我想在
react-router-dom
中使用NavLink在页面顶部显示登录按钮 这是导致问题的代码
import React, { Component } from 'react';
import logo from '../svg/logo.svg';
import {NavLink} from 'react-router-dom';
class Header extends Component {
render() {
return (
<div className="header-container">
<div className="header-top">
<img src={logo} alt="hdfhvbdhbhbvhxbc"/>
<NavLink className="signIn-btn">Sign In</NavLink>
</div>
</div>
);
}
}
export default Header;
if I comment out import {NavLink} from 'react-router-dom';
如果我注释掉
import {NavLink} from 'react-router-dom';
and <NavLink className="signIn-btn">Sign In</NavLink>
The code renders as intended.和
<NavLink className="signIn-btn">Sign In</NavLink>
代码按预期呈现。
When i run it in Vsstudio it shows that it has compiled successfully .当我在 Vsstudio 中运行它时,它显示它已成功编译。 However in my browser it shows me the following message
TypeError: toLocation is undefined
with the following additional messages但是在我的浏览器中,它向我显示以下消息
TypeError: toLocation is undefined
以及以下附加消息
51 | resolveToLocation(to, currentLocation),
52 | currentLocation
53 | );
> 54 | const { pathname: path } = toLocation;
| ^ 55 | // Regex taken from: https://github.com/pillarjs/path-to-regexp/blob/master/index.js#L202
56 | const escapedPath =
57 | path && path.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
I am using firefox btw我正在使用 firefox 顺便说一句
Just check the documentation : You are missing the "to" property in the NavLink
只需检查文档:您缺少
NavLink
中的“to”属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.