开发者

Faceoff: the ASP.NET MVC3 declarative, format stringstyle routing and node's imperitive routing

Here's an example node routing config:

var requestHandlers = require("./requestHandlers");

var handle = {}
handle["/"] = requestHandlers.start;
handle["/start"] = requestHandlers.start;
handle["/upload"] = requestHandlers.upload;

Its a mapping of URLs and request handlers. Simple, utilitarian, but what about the powerful format string syntax of MVC 3?

routes.MapRoute(
  "MediaRoute",               // Route name
  "{mediaTopic}/{mediaType}/{id}", // URL with parameters
  new { controller = "Media", action = "DisplayMediaItemById" },
  new { mediaType = "Article|Insight|Infographic" }

It allows for regexes in the {} variable names like mediaType, used in the route and defining its regex.

I'm sure adding regexes to node routing in some way will solve the disconnect. Maybe if someone made the MVC->开发者_开发知识库node transition they will have an answer. Have I missed any great node routing features?


If you just want to turn regexp on your route then look expressjs guide for the answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜