【发布时间】:2019-08-19 01:00:55
【问题描述】:
在子文件夹中使用 Apache 服务器部署 Angular 7 项目
Angular CLI: 7.3.1
Node: 11.1.0
OS: darwin x64
Angular: 7.2.4
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.13.1
@angular-devkit/build-angular 0.13.1
@angular-devkit/build-optimizer 0.13.1
@angular-devkit/build-webpack 0.13.1
@angular-devkit/core 7.3.1
@angular-devkit/schematics 7.3.1
@angular/cli 7.3.1
@ngtools/webpack 7.3.1
@schematics/angular 7.3.1
@schematics/update 0.13.1
rxjs 6.3.3
typescript 3.2.4
webpack 4.29.0
索引.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Flightslogic</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
App.routing:-
const routes: Routes = [
{ path: 'home', component: HomeComponent, pathMatch: 'full' },
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'about-us', component: AboutUsComponent, },
{ path: 'contact-us', component: ContactUsComponent, },
{ path: 'products/fare-app', component: ProductFareAppComponent, },
{ path: 'developer', component: ResourceDeveloperProgramComponent, }
];
@NgModule({
imports: [RouterModule.forRoot(routes), ],
exports: [RouterModule]
})
首页导航:
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link waves-light" href="#" mdbWavesEffect>Home
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link waves-light" mdbWavesEffect href="about-us">About</a>
</li>
<ul>
我想部署到带有子目录的 apache 服务器。我怎样才能做到这一点。 例如:http://www.example.com,子目录是 subdir。所以我想部署到http://www.example.com/subdir。我怎样才能实现它。
【问题讨论】:
-
在此处查看我的解决方案:stackoverflow.com/questions/39018765/…,如果有帮助,请为答案投票。
-
我试过了。但是当它写example.com/subdir时,它会路由到example.com/subdir/home并且页面会打开,但是如果我手动写example.com/subdir/home它会给出页面未找到错误
-
那么,在生产模式下,您必须包含一个
web.xml文件,它将404重定向到index.html,并且正常的角度路由将在生产模式下可用。
标签: angular deployment angular7