简体   繁体   中英

Import navigo using systemjs module

How can I import navigo using systemjs module? 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:

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 was exported in the form of 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. Therefore, the author of @types/navigo have to export Navigo with export = Navigo, the syntax which was designed to import commonjs module in TypeScript.

Navigo has been rewritten in TypeScript and exported as ES module. If you land here and still have problems try migrating to version 8.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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