Angular 2路由不能与ASP.net核心MVC
问题描述:
我正在使用Angular 2和VS 2015作为IDE的ASP.NET核心Web应用程序。这对我来说是全新的,所以我一直在关注每个教程以获得此页面的工作。当我终于把所有东西放在一起时,我面临着路由问题:页面停留在加载...标记中,并且从不在ModuleViewComponent中显示内容。阅读了很多*的问题,但我无法修复它。Angular 2路由不能与ASP.net核心MVC
我main.ts文件看起来像这样:
// main entry point
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
的app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule, Routes } from '@angular/router';
import { NgForm } from '@angular/forms';
import { AppComponent } from './app.component';
import { ModuleViewComponent } from './components/CommonComponents/moduleView.component/moduleView.component';
const myRoutes: Routes = [
{
path: 'home',
component: ModuleViewComponent
},
{
path: '/',
redirectTo: 'home',
pathMatch: 'full'
}
];
@NgModule({
imports: [
RouterModule.forRoot(myRoutes),
BrowserModule,
FormsModule,
HttpModule
],
declarations: [
AppComponent,
NavbarComponent,
ModuleViewComponent
],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template:'<router-outlet></router-outlet>'
})
export class AppComponent {
}
而index.cshtml
@{
ViewData["Title"] = "Home Page";
}
<my-app>loading...</my-app>
我怎样才能得到这个工作,并显示成分含量?任何帮助都比欢迎,提前谢谢。
答
我已经创建了一个示例应用程序,它解释了一步一步的详细信息,以使用Asp.net MVC框架创建角度(Angular v4)应用程序。以下是链接。希望这可以帮助你。您必须更新项目中的路由配置文件,以便角度可以接收请求。
http://hive.rinoy.in/angular4-and-asp-net-mvc-hybrid-application/
http://hive.rinoy.in/routing-in-angular-asp-net-mvc-application/
我要去尝试,我会让你知道 – Mig
提供的链接都死了。 – stckvflw
我已更新链接网址。请再检查一次。 – rinoy