我有一个网站,我用角度cli。我正在使用路由来切换内容。
我的问题是,当我输入例如:www.website.de/login
时,它会给我一个错误:404 Not Found
。我使用http-server . -p 80
运行此网站。我在服务器上有所有ng build --prog
个文件(dist)。但是,如果我使用ng serve
尝试使用localhost:4200/login
,我输入index.html
就行了。
以下是我重要的文件:
<body>
<script type="text/javascript" src="https://code.jquery.com/jquery2.1.4.min.js"></script>
<script src="assets/materialize/js/materialize.js"></script>
<home></home>
<script src="assets/script.js"></script>
</body>
home.component.html
<header>
<navbar></navbar>
</header>
<main>
<router-outlet></router-outlet>
</main>
<footer *ngIf="router.url != '/dashboard'" class="page-footer">
<footer-footer></footer-footer>
</footer>
app-routing.module.ts
import {NgModule} from "@angular/core";
import {RouterModule, Routes} from "@angular/router";
import {DashboardComponent} from "./Dashboard/dashboard.component";
import {ImprintComponent} from "./Imprint/imprint.component";
import {ContactUsComponent} from "./ContactUs/contactus.component";
import {LoginComponent} from "./Login/login.component";
import {StartComponent} from "./start/start.component";
import {ImpressumComponent} from "./Impressum/impressum.component";
const routes: Routes = [
{ path: '', redirectTo: '/', pathMatch: 'full' },
{ path: '', component: StartComponent },
{ path: 'imprint', component: ImprintComponent },
{ path: 'impressum', component: ImpressumComponent },
{ path: 'contact_us', component: ContactUsComponent },
{ path: 'login', component: LoginComponent },
{ path: 'dashboard', component: DashboardComponent }
];
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppRoutingModule{ }
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { DashboardComponent } from "./Dashboard/dashboard.component";
import { AppRoutingModule } from "./app-routing.module";
import {NavbarComponent} from "./Navbar/navbar.component";
import {ImprintComponent} from "./Imprint/imprint.component";
import {HomeComponent} from "./Home/home.component";
import {ContactUsComponent} from "./ContactUs/contactus.component";
import {LoginComponent} from "./Login/login.component";
import {FooterFooter} from "./Footer/footer.component";
import {HttpModule} from "@angular/http";
import { StartComponent } from './start/start.component';
import {ImpressumComponent} from "./Impressum/impressum.component";
@NgModule({
declarations: [
DashboardComponent,
NavbarComponent,
ImprintComponent,
HomeComponent,
ContactUsComponent,
LoginComponent,
FooterFooter,
StartComponent,
ImpressumComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpModule
],
providers: [],
bootstrap: [HomeComponent]
})
export class AppModule { }
spark.read.parquet(parquetPath).write.csv(newcsvPath)
此致
答案 0 :(得分:1)
使用ng serve
angular-cli使用引擎罩下的webpack-dev-server,它预先配置为将每个请求重定向到index.html
文件。这就是当您输入www.website.de/login
时它起作用的原因。它会重定向并返回index.html
,然后Angular启动并选取当前URL并执行路由。
现在,当您使用自定义服务器时,例如http-server
,它就不会这样做。您必须自己配置重定向。不幸的是,http-server
有is no easy way to do that。
我建议您将json-server用于静态文件而不是http-server
。它有一个简单的API,用于使用middleware配置重定向。