简体   繁体   English

使用CommonJS的反应路由器历史

[英]react-router history using CommonJS

The React-Router documentation shows that for including browser history you include it like such: React-Router文档显示,为了包括浏览器历史记录,您可以这样包含它:

import { browserHistory } from 'react-router'
. 
. 
.     
<Router history={browserHistory} />

How does one do this with CommonJS? CommonJS如何做到这一点?

When I try it using the import method I get Illegal import declaration while parsing file 当我尝试使用导入方法Illegal import declaration while parsing file

The import syntax isn't implemented in browsers yet (hence the error you're getting, I'd imagine), so you need a transpiler like Babel to use it. import语法尚未在浏览器中实现(因此,我会想到会出现错误),因此您需要像Babel这样的编译器才能使用它。 The equivalent CommonJS syntax is: 等效的CommonJS语法为:

var browserHistory = require("react-router").browserHistory

It mentions this on the GitHub page (although it doesn't specifically mention browserHistory ). 它在GitHub页面上提到了这一点(尽管它没有具体提到browserHistory )。

哼,您可以这样尝试:

var browserHistory = require('react-router').browserHistory

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

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