2016-11-22 2 views
2

Ich benutze Routing in eckigen 2 mit Typoskript.Pfad: "**" für nicht gefunden Seite

In Haupt index.html i hinzufügen <base href="">, nicht <base href="/">, weil ich für mein Projekt spezielle Route benötigen, und alles funktioniert, aber ich habe ein Problem mit nicht gefunden Seite. Hier ist ein Teil meines app.route.ts:

const appRoutes: Routes = [ 
    { component: LaskComponent, path: "table_per" }, 
    { component: LaskComponent, path: "table_per/:id" }, 
    { component: DashboardComponent, path: "dashboard" }, 
    { component: LoginComponent, path: "login" }, 
    { path: "", pathMatch: "full", redirectTo: "login" }, 
    { component: HomeComponent, path: "home" }, 
    { component: NotFoundComponent, path: "not_found" }, 
    { path: "**", redirectTo: "not_found" }, 
]; 
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes); 

Und das ist NotFoundComponent:

import { Component } from "@angular/core"; 
@Component({ 
    template: ' 
     <div class="container"> 
      <h1>Not found page</h1> 
     </div>', 
}) 
export class NotFoundComponent {}; 

Wenn ich ein Projekt in Chrom auf localhost beginnen, i zu localhost/login umleiten, und alles ist in Ordnung, aber wenn ich Überprüfen Sie eine nicht gefundene Seite wie diese localhost/sxvknb, ich bekomme diese Seite localhost/sxvknb/login und Redirect in Login-Formular erneut. Was ist das Problem? Vielleicht mit

{ path: "**", redirectTo: "not_found" } 

Einführung meines Projekt kann ich mit 3 beginnen setzt:

enter image description here

+0

Sie bieten können 'APP_BASE_HREF' anstelle von' 'http://stackoverflow.com/q Fragen/34535163/eckig-2-router-no-base-href-set/34535256 # 34535256 –

Antwort

1

Dies könnte Ihr Problem beheben:

import {APP_BASE_HREF} from '@angular/common'; 

@NgModule({ 
    declarations: [AppComponent], 
    bootstrap: [AppComponent], 
    imports: [BrowserModule, routing /* or RouterModule */], 
    providers: [{provide: APP_BASE_HREF, useValue : '/' }] 
]); 

Siehe auch Angular 2 router no base href set

+0

Mann, vielen Dank! –

+0

Gern geschehen. Freut mich das zu hören. –

+0

Sorry, kannst du mir sagen, wenn ich meine App in 'localhost' laucnh arbeite toll, aber wenn ich meine App vom Server starte:' 10.10.0.1/object/go' nehme ich eine nicht gefundene Seite von meiner Komponente, was ist das Problem? –