简体   繁体   English

使用 systemjs 模块导入 navigo

[英]Import navigo using systemjs module

How can I import navigo using systemjs module?如何使用 systemjs 模块导入navigo This is my code:这是我的代码:

import { Navigo } from 'navigo';

const router = new Navigo(null, true, '#!');
router.on({
    ........
}).resolve();

I couldn't import this package with modern ES6 syntax, had to use:我无法使用现代 ES6 语法import这个包,不得不使用:

let Navigo = require('navigo');

The reason that I have to import Navigo with this syntax is because of the way which Navigo exported itself.我必须使用这种语法导入 Navigo 的原因是 Navigo 导出自身的方式。

Navigo was exported in the form of UMD. Navigo 以 UMD 的形式导出。 And the way which was chosen to export Navigo to commonjs module loader is to replace the export object with the constructor function of Navigo.选择将 Navigo 导出到 commonjs 模块加载器的方式是将导出对象替换为 Navigo 的构造函数。 Therefore, the author of @types/navigo have to export Navigo with export = Navigo, the syntax which was designed to import commonjs module in TypeScript.因此,@types/navigo 的作者必须使用 export = Navigo 导出 Navigo,该语法旨在在 TypeScript 中导入 commonjs 模块。

Navigo has been rewritten in TypeScript and exported as ES module. Navigo 已用 TypeScript 重写并导出为 ES 模块。 If you land here and still have problems try migrating to version 8.如果您登陆这里但仍有问题,请尝试迁移到版本 8。

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

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