开发者

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

开发者 https://www.devze.com 2023-03-26 17:32 出处:网络
Here\'s an example node routing config: var requestHandlers = require(\"./requestHandlers\"); var handle = {}

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

精彩评论

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