Skip to content Skip to sidebar Skip to footer

Declare Routes In Sammy Js In Typescript

I would like to use the definitely typed sammyjs file in conjunction with typescript to declare a route on my page Javascript for the declaration would look like this -->

Solution 1:

I suspect the problem you have is that you are overriding Sammy's scope by using the fat-arrow syntax (which preserves your lexical scope).

var app: Sammy.Application = Sammy();
app.get('#:foobar', function () {
    //doStuff var baz = this.params.foobar;
});

By using "function" instead of "() =>" you avoid scope preservation and allow Sammy to work as usual.

Solution 2:

You can use lambda with parameter

varapp: Sammy.Application = Sammy();
app.get('#:foobar', context => {
    //doStuff var baz = context.params.foobar;
});

Post a Comment for "Declare Routes In Sammy Js In Typescript"