【发布时间】:2016-09-08 21:37:30
【问题描述】:
我在 ASP.NET MVC 5 项目中使用 AngularJS 2,我不使用 Angular 提供的路由,只依赖 MVC 路由策略。
奇怪的是,AngularJS 似乎会查看 URL,并且只有当我在路由 "domain/Controller" 上时才能正确加载,如果我在路由上是 "domain/ Controller/" 或 "domain/Controller/Action" 我的 Angular 应用程序未加载,我在浏览器中出现以下错误:
我正在使用以下脚本来加载我的引导程序:
<script src="~/Scripts/systemjs.config.js"></script>
<script>
System.import('../tsScripts/boot').catch(function (err) {
console.error(err);
});
</script>
我的 boot.ts 文件:
///<reference path="./../typings/globals/core-js/index.d.ts"/>
import {bootstrap} from '@angular/platform-browser-dynamic';
import {HTTP_PROVIDERS} from '@angular/http';
import {AppComponent} from './app';
bootstrap(AppComponent, [HTTP_PROVIDERS]);
我不知道为什么 Angular(或框架附带的其他部分)与 MVC 路由不兼容,或者我的实现有什么问题。
【问题讨论】:
-
Angular2 是一个单页应用程序框架,因此不使用它的路由器会破坏整个想法。看起来您的 SystemJs 配置有问题。
-
我怀疑它也在 SystemJS 配置文件中。您可能需要发布内容。它定义了从哪里下载文件。需要根据当前路线更新基本路径。 (但正如@rook 所提到的,鉴于 Angular 2 不打算在用户导航时一遍又一遍地加载,您不太可能这样做)。
-
这是我的 SystemJs 配置 pastebin.com/2JyvhcNK 我对 AngularJs 的 MV* 功能很感兴趣,但我想保留 ASP.NET MVC 的导航/路由/身份验证策略。但它似乎不是满足我需求的好工具。
标签: asp.net-mvc angular asp.net-mvc-5 routing