This question already has an answer here:
ES6 - Convert from 'require' to 'import'
                            
                                (1个答案)
                            
                    
                3年前关闭。
        

    

我将切换到ES6,现在我有这种担心。

var RouteHandler = require('react-router').RouteHandler;

我做了import RouteHandler from 'react-router'.RouteHandler,并且webpack给我一个错误。

那么,我应该如何导入呢?

最佳答案

尝试import {RouteHandler} from 'react-router'

或者,您可以执行以下操作:

import * as reactRouter from 'react-router';
var RouteHandler = reactRouter.RouteHandler;

10-06 00:23