2017-07-13 14 views
0

私のアプリをプロダクションサーバーのAngularに展開したいのですが、問題があります。アプリケーションは、角度ルーティング(コンポーネントの変更、リダイレクトなし)のみを使用しているが、ブラウザーでページを更新すると、コアページで動作します(IISをWebサーバーとして使用しているIISから404ページが返されます)Angular deployment - 404 on page Refresh

ルーティング:

const appRoutes: Routes = [ 
    { path: '', redirectTo: '/home', pathMatch: 'full', canActivate: [AuthGuard] }, 
    { path: 'home', component: DashboardComponent, canActivate: [AuthGuard] }, 
    { path: "profile", component: UserProfileComponent, canActivate: [AuthGuard] }, 
    { path: '400', component: ErrorComponent }, 
    { path: '401', component: ErrorComponent }, 
    { path: '403', component: ErrorComponent }, 
    { path: '404', component: ErrorComponent }, 
    { path: '500', component: ErrorComponent }, 
    { path: '503', component: ErrorComponent }, 
    { path: '**', redirectTo: '/404' } 
] 
+0

いくつかのルートに '[AuthGuard]'が実装されているので、 'providers:[AuthGuard、LoginService]'のように 'app.routing'ファイルで' providers'を使用して 'services'を登録する必要があります。あなたは '[AuthGuard]'のために使います。あなたはそれをやりました? – nivas

+0

経路はrouting.module.tsで定義され、app.moduleで使用するプロバイダはAuthGuardです。 routing.moduleのプロバイダであるか、app.module内のプロバイダのみである必要がありますか? – bluray

+0

@ routingモジュール.module.tsに@NgModuleデコレータで宣言する必要があります – nivas

答えて

2

私は私のアプリでweb.configファイルを変更:index.htmlをで

<configuration> 
    <system.webServer> 
<rewrite> 
    <rules> 
     <rule name="redirect all" stopProcessing="true"> 
      <match url="^(.*)$" ignoreCase="false" /> 
      <conditions logicalGrouping="MatchAll"> 
       <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" /> 
      </conditions> 
      <action type="Rewrite" url="./" appendQueryString="true" /> 
     </rule> 
    </rules> 
</rewrite> 
    </system.webServer> 
</configuration> 

<base href="./">です。ページをリフレッシュすることは現在OKです。

+0

これは、角度4とネットコア2.0で動作します。素晴らしい発見 –