nopCommerce is based on ASP.NET (MVC) and it follows the IRouteProvider
interface for registering the routes during the application start event. All the routes are registered in the “Route Provider” class in the Nop.Web project.
In order to view the “Route Provider” class, go to: Nop.Web/Infrastructure/RouteProvider.cs.
You will see the route registration of the pages like homepage, login & shopping cart etc:
using System.Web.Mvc; using System.Web.Routing; using Nop.Web.Framework.Localization; using Nop.Web.Framework.Mvc.Routes; namespace Nop.Web.Infrastructure { public partial class RouteProvider : IRouteProvider { public void RegisterRoutes(RouteCollection routes) { //We reordered our routes so the most used ones are on top. It can improve performance. //home page routes.MapLocalizedRoute("HomePage", "", new { controller = "Home", action = "Index" }, new[] { "Nop.Web.Controllers" }); //widgets //we have this route for performance optimization because named routes are MUCH faster than usual Html.Action(...) //and this route is highly used routes.MapRoute("WidgetsByZone", "widgetsbyzone/", new { controller = "Widget", action = "WidgetsByZone" }, new[] { "Nop.Web.Controllers" }); //MyNewPage routes.MapLocalizedRoute("ThisIsMyNewCustomPage", "MyNewPage/", new { controller = "MyNewPage", action = "Index" }, new[] { "Nop.Web.Controllers" }); //login routes.MapLocalizedRoute("Login", "login/", new { controller = "Customer", action = "Login" }, new[] { "Nop.Web.Controllers" }); //register routes.MapLocalizedRoute("Register", "register/", new { controller = "Customer", action = "Register" }, new[] { "Nop.Web.Controllers" }); //logout routes.MapLocalizedRoute("Logout", "logout/", new { controller = "Customer", action = "Logout" }, new[] { "Nop.Web.Controllers" }); //shopping cart routes.MapLocalizedRoute("ShoppingCart", "cart/", new { controller = "ShoppingCart", action = "Cart" }, new[] { "Nop.Web.Controllers" }); //wishlist routes.MapLocalizedRoute("Wishlist", "wishlist/{customerGuid}", new { controller = "ShoppingCart", action = "Wishlist", customerGuid = UrlParameter.Optional }, new[] { "Nop.Web.Controllers" });
You can use this “Route Provider” class for the following:
- Plugins custom routes
- New custom pages
Example of registering route for Contact us page in nopCommerce:
//contact us routes.MapLocalizedRoute("ContactUs", "contactus", new { controller = "Common", action = "ContactUs" }, new[] { "Nop.Web.Controllers" });
Hope it helps!
Looking for quality nopCommerce Web Hosting? Look no further than Arvixe Web Hosting!