简体   繁体   English

反应路由器 <Link> 无法正确反应16.8

[英]React-router <Link> doesn't work with react 16.8 correctly

Have a problem with react-router 5.0.0 and react 16.8 对react-router 5.0.0有问题并做出反应16.8

With NavLink app works as expected but with Link i got an error as 使用NavLink应用程序可以按预期工作,但是使用Link我得到了一个错误

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. 元素类型无效:期望使用字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。 You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. 您可能忘记了从定义文件中导出组件,或者可能混淆了默认导入和命名导入。

error message 错误信息

import React, { Component } from 'react';

import { Link } from 'react-router-dom';

import { Content } from '../../components/content/Content';

export class Home extends Component {
  render() {
    return (
      <Content>
        <Link to="/">Home Page</Link>
      </Content>
    );
  }
}

[SOLVED] I don't restart the app when converting functional component into class. [已解决]将功能组件转换为类时,我不会重新启动应用程序。 The first one doesn't have history prop provided by Router 第一个没有Router提供的history道具

From the error message: 从错误消息:

you might have mixed up default and named imports 您可能混淆了默认名称和命名导入

You should be mixing the import statement. 您应该混入import语句。 Follow the below convention to resolve your issue: 请遵循以下约定来解决您的问题:

import Content from '...';
// for a default export

Rather than a named export: 而不是命名的出口:

import { Content } from '...'
// for a named export

See these reference to understand the named export and default export: import and export 请参阅以下参考资料以了解命名的导出和默认导出: importexport

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM