【问题标题】:Angular app generating 404 on refresh deployed on weblogic url rewriting is enabledAngular 应用程序在 weblogic url 重写上部署的刷新时生成 404 已启用
【发布时间】:2018-04-14 00:32:51
【问题描述】:

我已经在 weblogic 服务器上部署了我的应用程序。我在 index.html 上重定向了 404 错误,但每当我尝试点击直接 URL 或刷新页面时,它第一次在网络中显示 404 错误。

这是一个 Angular 4 应用程序。

【问题讨论】:

标签: angular weblogic


【解决方案1】:

首先我会确保你将 useHash 变量设置为 true:

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

const routes: Routes = [//routes in here];

@NgModule({
    imports: [
    BrowserModule,
    FormsModule,
    RouterModule.forRoot(routes, { useHash: true })
    ],
    bootstrap: [AppComponent]
})
export class AppModule { }

然后对我有用的是尝试不同的基本 href 来查看哪个适用于 weblogic。如果刷新在 webpack 开发服务器上有效,那么您可能需要为 weblogic 使用不同的基本 href。您可以使用类似https://github.com/dzonatan/base-href-webpack-plugin 的方式使用 webpack 更改 baseref。

const { BaseHrefWebpackPlugin } = require('base-href-webpack-plugin');

// Add to plugins
plugins: [
   new HtmlWebpackPlugin(), // Required dependency
   new BaseHrefWebpackPlugin({ baseHref: '/' })
]

【讨论】:

    猜你喜欢
    • 2015-06-22
    • 1970-01-01
    • 2015-08-02
    • 2022-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-12
    相关资源
    最近更新 更多