简体   繁体   English

类型错误:props.history.listen 不是 function。 我正在使用 ReactJS

[英]TypeError: props.history.listen is not a function. I am using ReactJS

Why is this showing?为什么会出现这个? I am using ReacJS and I can not see what is wrong.我正在使用 ReacJS,但我看不出有什么问题。

My history.js:我的history.js:

import { createBrowserHistory } from 'history'

export default createBrowserHistory

My App.js:我的 App.js:

import React from 'react'
import { Router } from 'react-router-dom'

import Routes from './routes'
import history from './history'

import './styles/global.scss'

function App() {
  return (
    <div className="App">
      <Router history={history}>
        <Routes/>
      </Router>
    </div>
  );
}

export default App;

You need to invoke createBrowserHistory and then export it.您需要调用createBrowserHistory然后将其导出。 Try changing the line to:尝试将行更改为:

export default createBrowserHistory();

This is the proper way to import Router component,the root router component which takes history as a prop.这是导入Router组件的正确方法,Router组件是以历史为道具的根路由器组件。

import { BrowserRouter as Router } from "react-router-dom";

and as Sajib Khan said, you should also call the createBrowserHistory then use it as history prop.正如Sajib Khan所说,您还应该调用createBrowserHistory然后将其用作历史道具。

暂无
暂无

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

相关问题 为什么我得到 TypeError: _this.props.&quot;functionName&quot; is not a function ReactJS - Why am I getting TypeError: _this.props."functionName" is not a function ReactJS ReactJS 和 Twilio - 类型错误:this.props.history 未定义 - ReactJS and Twilio - TypeError: this.props.history not defined ReactJS 类型错误:this.props。 不是函数 - ReactJS TypeError: this.props. is not a function 我收到此错误我想使用 javascript 代码读取文件未捕获的类型错误:fs.readFile 不是 function。 我收到此错误 - I am getting this error I want to readfile using javascript code Uncaught TypeError: fs.readFile is not a function. I am getting this error TypeError: history.push 不是 function。在我的 opi udemy 课程中 - TypeError: history.push is not a function. In my opi udemy course ReactJS:未捕获的类型错误:this.props。 不是函数 - ReactJS: Uncaught TypeError: this.props. is not a function 未捕获的TypeError:this.props.onDelete不是函数reactjs - Uncaught TypeError: this.props.onDelete is not a function reactjs ReactJS:未捕获的TypeError:this.props.updateCommentText不是函数 - ReactJS: Uncaught TypeError: this.props.updateCommentText is not a function 为什么我收到 TypeError 而不是 function。 在数组 object 上调用 forEach - Why am I getting a TypeError not a function. Calling forEach on an array object 我收到未处理的拒绝(TypeError):router.transitionTo不是一个函数。 有什么可能是错的吗? - I am getting Unhandled Rejection (TypeError): router.transitionTo is not a function. What could possibly be wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM