CommonJS imports vs ES6 imports CommonJS imports vs ES6 imports reactjs reactjs

CommonJS imports vs ES6 imports


import ReactRouter only imports the default export. It does not import an object of named exports which is what you're attempting to achieve in your ES6 code. If there is no default export in the module, this ReactRouter will be undefined.

As stated, import { Link } from 'react-router' is the dedicated syntax for importing a single named export.

If you want to import all named exports into an object, you can use the import..as syntax:

import * as ReactRouter from 'react-router';var Link = ReactRouter.Link

MDN has a super-helpful list of all the different types of imports and how they work.