为什么导入{Thing}有效但不能导入Thing?

时间:2018-08-14 12:43:14

标签: javascript react-router

我正在观看有关Pluralsight的一些培训视频,所以我一定会接受。但是我也在做带薪工作(有10年Rails经验的优点)。这是在React中出现的,其中import Link from 'react-router-dom'仅用作import { Link } from 'react-router'dom。另外,我喜欢对SO进行检查。请原谅:)

1 个答案:

答案 0 :(得分:1)

这是命名导入和默认导入之间的区别:

import { Link } from 'react-router-dom'; // import the export named Link
import Link from 'react-router-dom'; // import the default export

进一步说明一下,如果您查看the file which handles the exports from react-router-dom,您会看到有很多命名的导出,但是没有默认值。如果有默认值,则:

import Link from 'react-router-dom';

将导入默认导出并将其命名为Link