2017-03-01 127 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