Create custom route overrides homepage views

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
I'm using nopCommerce version: 4.00. I'm trying to create a Plugin that overrides some views from homepage with my .cshtml. I've followed the guide for creating plugin from: http://docs.nopcommerce.com/pages/viewpage.action?pageId=1442493. I created controllers and views for that, but when I use this custom RouteProvider:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Nop.Web.Framework.Localization;
using Nop.Web.Framework.Mvc.Routing;

namespace Nop.Plugin.Misc.FacebookPixel.Infrastructure
{
    public partial class RouteProvider : IRouteProvider
    {
        /// <summary>
        /// Register routes
        /// </summary>
        /// <param name="routeBuilder">Route builder</param>
        public void RegisterRoutes(IRouteBuilder routeBuilder)
        {
            routeBuilder.MapLocalizedRoute("Plugin.Misc.FacebookPixel.HomePage",
                "",
                new {controller = "Home", action = "Index"},
                new[] { "Nop.Plugin.Misc.FacebookPixel.Controllers" });
        }

        /// <summary>
        /// Gets a priority of route provider
        /// </summary>
        public int Priority => int.MaxValue;
    }



it causes:

An error occurred while starting the application.
RouteCreationException: The constraint entry 'Length' - '1' on the route '' must have a string value or be of a type which implements 'Microsoft.AspNetCore.Routing.IRouteConstraint'.

Microsoft.AspNetCore.Routing.RouteConstraintBuilder.AddConstraint(string key, object value)
RouteCreationException: An error occurred while creating the route with name 'Plugin.Misc.FacebookPixel.HomePage' and template ''.

Microsoft.AspNetCore.Routing.RouteBase..ctor(string template, string name, IInlineConstraintResolver constraintResolver, RouteValueDictionary defaults, IDictionary<string, object> constraints, RouteValueDictionary dataTokens)

RouteCreationException: The constraint entry 'Length' - '1' on the route '' must have a string value or be of a type which implements 'Microsoft.AspNetCore.Routing.IRouteConstraint'.
        Microsoft.AspNetCore.Routing.RouteConstraintBuilder.AddConstraint(string key, object value)
        Microsoft.AspNetCore.Routing.RouteBase.GetConstraints(IInlineConstraintResolver inlineConstraintResolver, RouteTemplate parsedTemplate, IDictionary<string, object> constraints)
        Microsoft.AspNetCore.Routing.RouteBase..ctor(string template, string name, IInlineConstraintResolver constraintResolver, RouteValueDictionary defaults, IDictionary<string, object> constraints, RouteValueDictionary dataTokens)


I need help solving this error, I don't know what happens. Thank you
5 years ago
routeBuilder.MapLocalizedRoute("Plugin.Misc.FacebookPixel.HomePage",
                "",
                new {controller = "Home", action = "Index"},null,
                new[] { "Nop.Plugin.Misc.FacebookPixel.Controllers" });

By using this resolve that issue.
But it goes to the Nop default routing
5 years ago
Did anyone ever solve this? I am facing the same issue trying to override a customer route.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.