简体   繁体   English

我在我的反应项目中收到此错误“TypeError: toLocation is undefined”

[英]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.

相关问题 我在我的 React 项目中收到此错误“TypeError: Cannot read property 'map' of undefined” - I'm getting this error “TypeError: Cannot read property 'map' of undefined” on my React project 我收到错误:运行我的反应项目时无法读取未定义的属性'then' - I get the error : Cannot read property 'then' of undefined when I run my react project 我在使用 React 制作的项目中遇到未定义的错误 - I'm getting an undefined error in my project made with React TypeError: undefined is not an object (evalating '_this.props') in my react native project - TypeError: undefined is not an object (evaluating '_this.props') in my react native project 我的反应代码正在工作,但是当我刷新页面时,我得到 TypeError: Cannot read property 'Location' of undefined - my react code is working but when i refresh the page i get TypeError: Cannot read property 'Location' of undefined 我收到错误:-未处理的拒绝(TypeError):无法读取 React 应用程序中未定义的属性“id” - I get the error : - Unhandled Rejection (TypeError): Cannot read property 'id' of undefined in React Application 运行我的nodejs代码时收到此错误:&#39;TypeError:无法读取未定义的属性&#39;apply&#39;。 &#39; - I get this error when running my nodejs code: ' TypeError: Cannot read property 'apply' of undefined. ' 我在React API组件中得到一个未定义的 - I get a undefined in my React API component “ TypeError: Cannot read property 'map' of undefined ” 当我在 react 中使用迭代数组的响应列表时出现此错误 - “ TypeError: Cannot read property 'map' of undefined ” I get this error when I using iterate the response list of array in react 我的错误控制台中出现未定义的错误 - I get an undefined error in my error console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM