私はこれでしばらくの間戦っていて、投稿を書くことに決めました。ASP.Net Core + Angular 2 app/home routing
私は、ASP.NET Core Template Packから取得したテンプレートに対して、ASP.Net Core 5.0とAngular 2のVS2017を使用して単純なシングルページアプリケーションを構築しています。アプリケーションは連絡先リストデータベースを管理することになっています。
私が念頭に置いて考えているのは、デフォルトの開始 '/ home'ページがHomeComponentを使用して連絡先のリストを表示しているということです。すべてのルーティングはうまく動作しますが、アプリが起動しているときや、「/ home」にルーティングしようとしているときは、Angularルーティングを使用する代わりにASPホームビューのIndex.cshtmlページに移動し続けます。
どのようにすればいいのでしょうか?私はHomeComponentを '/ home'ルートに揃えたいと思っていましたが、代わりにASPページに移動し続けます。そこには、私が本当に必要としない「Loading ...」としか言いようがありません。
私はさまざまな解決方法を試しましたが、何もできませんでした。
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true
});
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index" });
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index",});
});
}
:私はここにStartup.csからの私の設定方法だ、;-)
をしてくださいあなたは基本的にそれを維持することができますので、もし私は、これらの理由で、あまりにも進んでいないんだと、ここで何かを明らかに不足している可能性があります
app.module.shared.ts:
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { AppComponent } from './components/app/app.component'
import { NavMenuComponent } from './components/navmenu/navmenu.component';
import { DetailsComponent } from './components/details/details.component';
import { EditComponent } from './components/editContact/editContact.component';
import { NewContactComponent } from './components/newContact/newContact.component';
import { HomeComponent } from './components/home/home.component';
import { ContactServices } from './services/services';
export const sharedConfig: NgModule = {
bootstrap: [ AppComponent ],
declarations: [
AppComponent,
NavMenuComponent,
DetailsComponent,
EditComponent,
NewContactComponent,
HomeComponent
],
providers: [ContactServices],
imports: [
RouterModule.forRoot([
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'details', component: DetailsComponent },
{ path: 'new', component: NewContactComponent },
{ path: '**', redirectTo: 'home' }
])
]};
ASPのホームIndex.cshtml:
@{
ViewData["Title"] = "Home Page";
}
<app>Loading...</app>
<script src="~/dist/vendor.js" asp-append-version="true"></script>
@section scripts {
<script src="~/dist/main-client.js" asp-append-version="true"></script>
}
Aaaandホme.component.ts:
import { Component } from '@angular/core';
import { ContactServices } from '../../services/services';
import { Response } from '@angular/http';
@Component({
selector: 'home',
templateUrl: './home.component.html'
})
export class HomeComponent {
public ContactList = [];
public constructor(private conService: ContactServices) {
this.conService.getContactList()
.subscribe(
(data: Response) => (this.ContactList = data.json())
);
}
}
ありがとうございました!アドバイスをいただければ幸いです。
これは実際に私の質問に答えるものではありませんが、OK: - )... 私はプログラミングを学んでいますので、私は移動するためにオンラインで見つけたものに頼っています。私が提供する必要があるプロジェクトは、ASP.NET CoreとAngular2要素の単純な組み合わせです。私は終わりに近づいていますが、このルーティングの問題は、私が動作させたいと思っているように、セットアップから離れてしまいます。 もちろん、私はすでにAngular-CLIに関する資料を見つけましたので、これを学習の機会としましょう。それでも、私はルーティング問題を解決するためのヒントをお伝えしたいと思います:-) – WAR
コンポーネントからのセレクタであるため、「読み込み中...」と表示されているASPページが必要です。 aspページが "Loading ..."になっている場合は、正しいコンポーネントが選択されていません。またiisを使用している場合は、おそらくこのリンクが役立ちますhttps://stackoverflow.com/questions/22656945/set-index-html-as-the-default-page – HelpinCodingpls
また、出口 – HelpinCodingpls