谢谢大家。我分享我的工作配置
//Ưu tiên Search
routes.MapRoute(name: "search", url: "{lang}/search/{keyword}", defaults: new { controller = "search", action = "result" });
//Normal with Language
routes.MapRoute(
name: "Language",
url: "{lang}",
defaults: new { controller = "Home", action = "Index", lang = UrlParameter.Optional },
constraints: new { lang = @"(\w{2})" }
);
//News Category
routes.MapRoute(
name: "defaultLanguageWithCate",
url: "{cateSlug}",
defaults: new { lang = "vi", controller = "News", action = "NewsByCate" },
constraints: new { lang = @"(\w{2})", controller = "News", action = "NewsByCate" },
namespaces: new[] { "Frontend.Web.Controllers" }
);
routes.MapRoute(
name: "languageWithCate",
url: "{lang}/{cateSlug}",
defaults: new { lang = "vi", controller = "News", action = "NewsByCate" },
constraints: new { lang = @"(\w{2})", controller = "News", action = "NewsByCate" },
namespaces: new[] { "Frontend.Web.Controllers" }
);
//News Detail
routes.MapRoute(
name: "defaultLanguageWithArticle",
url: "{cateSlug}/{articleSlug}",
defaults: new { lang = "vi", controller = "News", action = "Detail" },
constraints: new { lang = @"(\w{2})", controller = "News", action = "Detail" },
namespaces: new[] { "Frontend.Web.Controllers" }
);
routes.MapRoute(
name: "languageWithArticle",
url: "{lang}/{cateSlug}/{articleSlug}",
defaults: new { lang = "vi", controller = "News", action = "Detail" },
constraints: new { lang = @"(\w{2})", controller = "News", action = "Detail" },
namespaces: new[] { "Frontend.Web.Controllers" }
);
//Không có Language
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, lang = "vi" }
);
什么是控制器的方法与每个相关联,你想让url看起来像什么?例如5号,你想要'../ fr/News/Detail/10'(或者也许只是'..fr/Details/10')来显示'ID = 10'的News项目的细节用法语? –
对于那些不熟悉Drupal的人来说,这个问题相当模糊,但[这个答案](http://stackoverflow.com/a/32839796/181087)可能会让你朝正确的方向发展。 – NightOwl888
{root}/{catePermanentLink}/{newsPermanentLink} ==>使用默认语言的新闻细节。 {root}/fr/{catePermanentLink}/{newsPermanentLink} ==>使用FR语言的新闻细节 – Linc