簡體   English   中英

使用CommonJS的反應路由器歷史

[英]react-router history using CommonJS

React-Router文檔顯示,為了包括瀏覽器歷史記錄,您可以這樣包含它:

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

CommonJS如何做到這一點?

當我嘗試使用導入方法Illegal import declaration while parsing file

import語法尚未在瀏覽器中實現(因此,我會想到會出現錯誤),因此您需要像Babel這樣的編譯器才能使用它。 等效的CommonJS語法為:

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

它在GitHub頁面上提到了這一點(盡管它沒有具體提到browserHistory )。

哼,您可以這樣嘗試:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM