React路由器不显示浏览器历史记录 [英] React router not showing browser history

查看:20
本文介绍了React路由器不显示浏览器历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习这个教程,但我不断收到此错误:

I'm learning from this tutorial but I keep getting this error:

'react-router' 不包含名为 'browserHistory' 的导出.

'react-router' does not contain an export named 'browserHistory'.

有 react-router 的文件是这样的:

The file that has react-router is this:

import React from 'react';
import ReactDOM from 'react-dom';
import { Router, browserHistory } from 'react-router';
import routes from './routes';

ReactDOM.render(
  <Router history={browserHistory} routes={routes} />, 
  document.getElementById('root')
);

推荐答案

您需要从 browserHistorynoreferrer">history 模块现在.

You need to get browserHistory from the history module now.

import createHistory from 'history/createBrowserHistory'

请注意,他们最近更改了模块 API,因此如果您使用的是最新版本,导入会略有变化:

Note that they changed the module API recently so if you are using the latest version the import slightly changed:

import { createBrowserHistory } from 'history'

这篇关于React路由器不显示浏览器历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆