Skip to main content


Showing posts from November, 2014

Strong typed MVC routing on TypeScript/JavaScript

Very often we mess up with routing by giving path which does not exist due to various reason like spelling mistake, name confusions etc. for forming correct URLs . This happens on both server side codes and client side code. There are few strong typed routing provider library present for server side but none is present on the client side. We will look into creating a classes and function to set up our routing paths which will help us to give correct URL based on MVC routing. The idea is to create T4 template file which will be generating client side codes based on MVC routing. I have tried to keep it simple in this version which reads up MVC controllers and public function. The end result looks like this, which is TypeScript code. Makes it pretty simple to use these classes directly without worrying about correct URLs. module Routing { export declare var DomainName: string; export function GetDomainName(): string { return (DomainName != undefined &&