1

に取り組んでいない私は、次のルートの設定とNgModule app.module.tsでAngularCliアプリケーションルートは生産

アプリ-routing.module.tsオン

import { NgModule } from '@angular/core'; 
import { Routes, RouterModule } from '@angular/router'; 
import { OneComponent } from './components/one.component'; 
import { TwoComponent } from './components/open/two.component'; 

const routes: Routes = [ 

    { path: '', redirectTo: 'one', pathMatch: 'full' }, 
    { path: 'one', component: OneComponent }, 
    { path: 'two', component: TwoComponent }, 
    { path: '**', redirectTo: 'one' } 

]; 

@NgModule({ 
    imports: [RouterModule.forRoot(routes, { useHash:false })], 
    exports: [RouterModule] 
}) 

export class AppRoutingModule { } 

とAngularCliとの角度のアプリを持っている

import { LocationStrategy, PathLocationStrategy } from '@angular/common'; 
@NgModule({ 
    declarations: [ 
    AppComponent, 
    OneComponent, 
    TwoComponent  
    ] 
    imports: [  
    AppRoutingModule, 
    ], 
    bootstrap: [AppComponent], 
    providers: [{ provide: LocationStrategy, useClass: PathLocationStrategy }] 
}) 

開発モードではルートは問題ありませんが、本番用に行くと(ng build --prod --aot)ルートが機能しなくなります。 私がHashLocationStrategyルートを使用する場合は、開発モードと運用モードの両方で動作しますが、時にはURLを2〜3回ヒットする必要があるため、いくつかの問題があります。
PathLocationStrategyが私に私が欲しいと思う行動だけではなく、開発と生産ではない。

は、私はあなたがIISでWebアプリケーションをデプロイしている場合、事前

+0

開発モードでアプリをどのように構築して使用していますか? ng serve -oを使用していますか?いつものようにdev(ng serve)の – RRForUI

+0

。デプロイメント(ng build --prod --aot) –

答えて

0

私は私のasp.netのコアアプリケーションのweb.configファイルにこれを追加する必要がAngular.ioサイト Go here

により提供されたものと同じ溶液で、この問題を修正終わった:

<system.webServer> 
    <rewrite> 
    <rules> 
     <rule name="Angular Routes" stopProcessing="true"> 
     <match url=".*" /> 
     <conditions logicalGrouping="MatchAll"> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="/" /> 
     </rule> 
    </rules> 
    </rewrite> 
</system.webServer> 

<action type="Rewrite" url="/"/>のURLはindex.htmlのベースhrefと一致する必要があります

0

に問題

任意のアイデア、感謝せずに両方のモードで機能するソリューションを必要とし、空のHREFタグを入れてみてください、その後、アプリを構築および展開

<base href=""> 
+0

私は試してみます –

+0

問題が続く –

0

サーバー上のAngularアプリへのパスとは何ですか? index.htmlファイルの最初のURLが "www.example.com/my/anular/app/"の場合、index.htmlには<base href="/my/angular/app/">が必要です。 --base-href /my/angular/app/ng buildに追加します。先頭と末尾のスラッシュは重要です。

+0

私のシングルページアプリケーションを含むwwwrootフォルダを持つAsp.net Core Apiアプリケーションですか? AngularプロジェクトはAsp.net Core Apiから分離していますが、私はAsp.net Core Apiのwwwrootフォルダに展開します –