2017-03-01 125 views
0

我最近在vs2015和IIS 7.5中聲明瞭一個角2項目。 我刷新頁面時出現問題,當我刷新頁面時,我收到刷新404錯誤的角2 + IIS

「HTTP錯誤404.0 - 未找到」。

這裏是我的角度代碼: index.html中我有

<script>document.write('<base href="' + document.location + '" />');</script> 

在app.module.ts

import { NgModule }  from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 

import { HttpModule } from '@angular/http'; 
import { RouterModule } from '@angular/router'; 

import { AppComponent } from './app.component'; 
import { HomeComponent } from './components/home/home.component'; 

import { HomeModule } from './modules/home.module'; 
import { CodesModule } from './modules/codes.module'; 
import { AdminModule } from './modules/admin.module'; 

@NgModule({ 
    imports: 
    [ 
     BrowserModule, 
     HttpModule, 
     RouterModule.forRoot([ 
      { path: 'home', component: HomeComponent }, 
      { path: 'home/:unauthorized', component: HomeComponent }, 
      { path: '', redirectTo: 'home', pathMatch: 'full' }, 
      { path: '**', redirectTo: 'home', pathMatch: 'full' }, 
     ]), 
     HomeModule, 
     CodesModule, 
     AdminModule 
    ], 
    declarations: 
    [ 
     AppComponent, 
     HomeComponent 
    ], 
    bootstrap: [ AppComponent ] 
}) 
export class AppModule { } 

而其他moduls:

import { NgModule } from '@angular/core'; 

import { RouterModule } from '@angular/router'; 

import { CodesComponent } from '../components/codes/codes.component'; 

@NgModule({ 
    declarations: 
    [ 
     CodesComponent 
    ], 
    imports: 
    [ 
     RouterModule.forChild([ 
      { path: 'codes', component: CodesComponent }, 
     ]) 
    ] 
}) 
export class CodesModule { 

} 

import { NgModule } from '@angular/core'; 

import { RouterModule } from '@angular/router'; 

import { AdminCompoment } from '../components/admin/admin.component'; 

@NgModule({ 
    declarations: 
    [ 
     AdminCompoment 
    ], 
    imports: 
    [ 
     RouterModule.forChild([ 
      { path: 'admin', component: AdminCompoment }, 
     ]) 
    ] 
}) 
export class AdminModule { 

} 

當我嘗試使用哈希標記正常工作,但我不想噸o使用有標籤。 我試圖在IIS中重寫規則,但當我刷新一些頁面時,我只重定向到主頁面。

請幫忙。 謝謝。

回答

1

已解決。 步驟:

  1. 在web.config中 用行動改寫添加這樣 <action type="Rewrite" url="/eUsluge.Administration.UI/" appendQueryString="true" />

  2. 的Index.html添加此

<base href="/Application/" />

+0

嗨,在web.config中的這個應該添加? – prestonsmith

+0

這裏 <規則名稱= 「AngularJS」 stopProcessing = 「真」> <匹配URL = 「^(。*)$」 IGNORECASE = 「假」/> <條件logicalGrouping = 「MatchAll」> <動作類型= 「重寫」 URL = 「以下」 appendQueryString = 「真」/> user3118955

+0

'eUsluge.Administration.UI'的值是什麼以及它來自哪裏? – Neutrino