javascript - React-router <Link> 无法正确使用 React 16.8

标签 javascript reactjs react-router react-hooks

react-router 5.0.0和react 16.8有问题

使用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>
    );
  }
}

[已解决] 将功能组件转换为类时,我不会重新启动应用程序。第一个没有 Router 提供的 history 属性

最佳答案

来自错误消息:

you might have mixed up default and named imports

您应该混合导入语句。请遵循以下约定来解决您的问题:

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

而不是命名导出:

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

请参阅这些引用资料以了解命名导出和默认导出:importexport

关于javascript - React-router <Link> 无法正确使用 React 16.8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55326158/

相关文章:

javascript - 使用 jQuery 在 mousedown 函数中绑定(bind) mousemove

javascript - DIV 调节 - 检查 DIV 中是否存在 IMG

javascript - Electron webview 仅预加载文件 ://protocol is supported when using create-react-app base

javascript - 即使状态发生变化,页面刷新后 React 也不会重新渲染组件

reactjs - 路由更改时重置组件的内部状态

javascript - react native : How to pass props navigating from one screen to another

javascript - AVM2 和 ABC(Adobe 的 ActionScript 字节码格式)规范许可..我可以使用它吗?

Javascript FQL : filtering by "created_time", 几次调用后 (moSTLy 1),没有返回结果

javascript - 如何创建一个动态列表,其中的元素描述仅在单击元素时显示?

javascript - React/react-router 重定向到一组 URL?