【问题标题】:Angular 2 + IIS on refresh 404 errorAngular 2 + IIS 刷新 404 错误
【发布时间】:2017-07-20 15:42:17
【问题描述】:

我最近在 vs2015 和 IIS 7.5 中陈述了一个 Angular 2 项目。 我在刷新页面时遇到问题,当我刷新页面时,我得到了

“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 { }

还有其他模块:

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 {

}

当我尝试使用哈希标签时,它可以正常工作,但我不想使用 has 标签。 我尝试在 IIS 中重写规则,但是当我刷新某些页面时,我只有重定向到主页。

请帮忙。 谢谢。

【问题讨论】:

    标签: angular visual-studio-2015 iis-7.5 angular2-routing


    【解决方案1】:

    解决了。 步骤:

    1. 在 web.config 中添加重写 用这样的动作 &lt;action type="Rewrite" url="/eUsluge.Administration.UI/" appendQueryString="true" /&gt;

    2. Index.html 添加这个

    &lt;base href="/Application/" /&gt;

    【讨论】:

    • 嗨,这应该在 web.config 中的哪个位置添加?
    • 这里
    • 'eUsluge.Administration.UI' 的值是什么?它从何而来?
    猜你喜欢
    • 2017-10-02
    • 2018-11-27
    • 2019-01-29
    • 2017-09-09
    • 2019-01-10
    • 2019-08-06
    • 2023-03-17
    • 2018-11-07
    • 1970-01-01
    相关资源
    最近更新 更多