在我的新项目中,WebApi2我使用 Angular2 框架。配置和添加角度后,我尝试调用第一个组件。还有我的问题。如何将角度路由与 webapi2 连接?我在添加路由的地方添加了新类:我<home-page>在 MVC 控制器视图中调用Index.cshtml
app.routing.ts
const appRoutes: Routes = [
{ path: 'home', component: HomePage },
{ path: 'test', component: AppComponent}
];
app.component.ts
@Component({
selector: 'my-app',
templateUrl: './app.template.html',
})
主页.component.ts
@Component({
selector: 'home-page',
templateUrl: './HomePage.template.html',
providers: [GetContent]
})
system.config.js
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the Angular folder
'app': 'Angular',
// angular bundles ...
}
meta: {
'./*.js': {
loader: '/systemjs-angular-loader.js'
}
}
共享 _Layout.cshtml
<script src="/node_modules/core-js/client/shim.min.js"></script>
<script src="/node_modules/zone.js/dist/zone.js"></script>
<script src="/node_modules/systemjs/dist/system.src.js"></script>
<script src="/systemjs.config.js"></script>
<script>
System.import('Angular/main.js').catch(function (err) { console.error(err); });
</script>
我将它包含app.module.ts在导入部分。当我启动应用程序时,我会看到来自HomePage组件的信息,但是当我添加路由路径时/test,它会将我重定向到HomePage组件。我在哪里犯了错误?