角路由器无法匹配任何路由

时间:2020-07-31 10:50:53

标签: c# angular routes

我在我的VS解决方案中的一个视图中集成了一个角度应用程序。但是,当前无法识别应用程序的路由入口点,因此无法加载该应用程序。我认为这可能与我的c#路由与角度路由冲突有关。

我在控制台中收到此错误消息:

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'home/ExpertAdvice'
Error: Cannot match any routes. URL Segment: 'home/ExpertAdvice'

我的角度布线模块:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router'; // CLI imports router

import { ExpertAdviceLandingPageComponent } from './expert-advice-landing-page/expert-advice-landing-page.component';
import { BuyingGuideComponent } from './buying-guide/buying-guide.component';
import { AdviceAndGuidanceComponent } from './advice-and-guidance/advice-and-guidance.component';
import { IdeasAndInspirationComponent } from './ideas-and-inspiration/ideas-and-inspiration.component';

const routes: Routes = [
    { path: 'Home/Expertadvice', component: ExpertAdviceLandingPageComponent },
    { path: 'buying-guide', component: BuyingGuideComponent },
    { path: 'advice-and-guidance', component: AdviceAndGuidanceComponent},
    { path: 'ideas-and-inspiration', component: IdeasAndInspirationComponent}

]; // sets up routes constant where you define your routes

// configures NgModule imports and exports
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

捆绑了应用并构建用于生产后的视图:

@{
    ViewBag.Title = "Expert Advice";
    PageData["AdditionalStyleBundle"] = "/Bundles/en-US/styles.43f1411b9bd5c181077b.css";

    var shop = new LogicShop.Shop();
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>angular app</title>
</head>
<body>
    <div>
        <app-root></app-root>
    </div>
    <script src="/Bundles/en-US/main-es5.0aef0c42f9564810310d.js"></script>
    <script src="/Bundles/en-US/main-es2015.0aef0c42f9564810310d.js"></script>
    <script src="/Bundles/en-US/polyfills-es5.0fd315f8e8919478eabf.js"></script>
    <script src="/Bundles/en-US/polyfills-es2015.9a4d92773ea40b444455.js"></script>
    <script src="/Bundles/en-US/runtime-es5.48d4dd272c393b14e6b7.js"></script>
    <script src="/Bundles/en-US/runtime-es2015.48d4dd272c393b14e6b7.js"></script>
    <script src="/Bundles/en-US/scripts.cc5d7fb76aa54d397727.js"></script>
</body>

<script type="text/javascript">
    /* curator-feed-default-layout */
    (function () {
        var i, e, d = document, s = "script"; i = d.createElement("script"); i.async = 1;
        i.src = "https://cdn.curator.io/published/ccc71ec0-ceff-435f-9343-7e5d29f5b570.js";
        e = d.getElementsByTagName(s)[0]; e.parentNode.insertBefore(i, e);
    })();
</script>

</html>

应用未加载:

enter image description here

Routeconfig:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace WebShopSterlingbuild
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapMvcAttributeRoutes();
           
            routes.MapRoute(
                name: "CategoryHome",
                url: "category/",
                defaults: new { controller = "Home", action = "CategoryHome", id = UrlParameter.Optional });
            routes.MapRoute(
              name: "Decode",
              url: "{*theregex}",
              defaults: new { controller = "Home", action = "Decode", },
              constraints: new { theregex = @"^[a-zA-Z0-9]{10}$" });
            routes.MapRoute(
                name: "Category",
                url: "category/{id}",
                defaults: new { controller = "Home", action = "Category", id = UrlParameter.Optional });

            routes.MapRoute(
                name: "Category-Amp",
                url: "Category-Amp/{id}",
                defaults: new { controller = "Home", action = "Category-Amp", id = UrlParameter.Optional });

            routes.MapRoute(
                name: "Page",
                url: "page/{id}",
                defaults: new { controller = "Home", action = "Page", id = UrlParameter.Optional });

            routes.MapRoute(
                name: "Info",
                url: "info/{id}",
                defaults: new { controller = "Home", action = "Info", id = UrlParameter.Optional });

            routes.MapRoute(
                name: "CaseStudies",
                url: "case-studies/{id}",
                defaults: new { controller = "Home", action = "CaseStudy", id = UrlParameter.Optional });

            routes.MapRoute(
                name: "CaseStudy",
                url: "case-study/{id}",
                defaults: new { controller = "Home", action = "Info", id = UrlParameter.Optional });

            routes.MapRoute(
                name: "Info-Amp",
                url: "Info-Amp/{id}",
                defaults: new { controller = "Home", action = "Info-Amp", id = UrlParameter.Optional });

            routes.MapRoute(
                name: "Infosearch",
                url: "Infosearch/{id}",
                defaults: new { controller = "Home", action = "InfoSearch", id = UrlParameter.Optional });

            routes.MapRoute(
                name: "Search",
                url: "search/{id}",
                defaults: new { controller = "Home", action = "Search", id = UrlParameter.Optional });

            routes.MapRoute(
                name: "Basket",
                url: "basket/{id}",
                defaults: new { controller = "Home", action = "Basket", id = UrlParameter.Optional });

            routes.MapRoute(
                name: "Sitemap",
                url: "sitemap.xml",
                defaults: new { controller = "Home", action = "Sitemap" });

            routes.MapRoute(
                name: "RegisterNewsletter",
                url: "registernewsletter/{id}",
                defaults: new { controller = "Home", action = "RegisterNewsletter", id = UrlParameter.Optional });

            // used to redirect mapping URLs that have more than 3 paremters (/param1/param2/param3/param4) - this allow the error to be picked up by ASP.NET rather than IIS
            routes.MapRoute(
                name: "Custom10",
                url: "{controller}/{action}/{id}/{param4}/{param5}/{param6}/{param7}/{param8}/{param9}/{param10}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, param3 = UrlParameter.Optional, param4 = UrlParameter.Optional, param5 = UrlParameter.Optional, param6 = UrlParameter.Optional, param7 = UrlParameter.Optional, param8 = UrlParameter.Optional, param9 = UrlParameter.Optional, param10 = UrlParameter.Optional });
           
            // default - probably not in use due to the redirect mapping above
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

在我的家庭控制器中,我具有此功能,该功能返回角度应用程序的相关视图:

   public ActionResult ExpertAdvice(InfoViewModel viewModel, string preview)
    {
        return View(viewModel);
    }

0 个答案:

没有答案