I am trying to create a simple routing application using sammyjs written in Typescript and systemjs as module loader.
However facing issues with loading of sammy.
Below are the code snippets
SystemJs Config
System.config({
transpiler: "typescript",
defaultJSExtensions: true,
map: {
"knockout": "../bower_components/knockout/dist/knockout",
"sammy": "../bower_components/sammy/lib/sammy",
"jquery": "../bower_components/jquery/dist/jquery"
}
});
Route Provider
import { Route } from "./types";
import * as Sammy from "sammy"
export class RouteProvider {
sammyApp: Sammy.Application;
defaultRoute: string;
constructor() {
}
configureRoutes = (routes: Array<Route>) => {
this.sammyApp = Sammy(() => {
routes.map((_route: Route) => {
this.sammyApp.get('#' + _route.path, (context) => {
_route.callBack(context);
});
})
});
this.sammyApp.run('#' + this.defaultRoute);
}
}
When i initialize the RouteProvider class and call configureRoutes method i am getting below error,
Uncaught TypeError: Sammy is not a function
I checked the network tab in the browser and sammy.js has been loaded. Also I am getting proper type definitions and there is no Typescript compilation error.