2017-07-09 128 views
2

由於有些天,我有Angular CLI和路由這個問題。 如果你指向確切的網址,它似乎工作正常。 當您嘗試使用routerLink重定向時,它會在url中寫入無限/#頁面。 如果你是指數,並嘗試去了解頁面寫入http://baseurl/index#/about#/index#/index#/index#/index#/index#/index#/index#/ ...並一直持續到結束的RAM:d角度4路由與無限/#/在url

這個問題只有在與「吳服」 DEVMODE(但hashlocationstrategy作品)。在生產模式似乎工作正常。

這裏有一些代碼。

index.html中

<base href="/"> 

app.module

import { NgModule } from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 
import { RouterModule } from '@angular/router'; 

import { AppComponent } from './app.component'; 

import { ConnectionService, ownerEnums, requestIdEnums } from './services/connection.service'; 
import { AuthService } from './services/auth.service'; 

import { AboutComponent } from './about/about.component'; 
import { ConnectComponent } from './connect/connect.component'; 
import { LayoutComponent } from './layout/layout.component'; 

import { HeaderComponent } from './layout/header/header.component'; 
import { BreadcrumbComponent } from './layout/breadcrumb/breadcrumb.component'; 
import { FooterComponent } from './layout/footer/footer.component'; 
import { IndexComponent } from './layout/index/index.component'; 

@NgModule({ 
    imports: [ 
    RouterModule.forRoot([ 
    { path: '', redirectTo: '/index', pathMatch: 'full' }, 
    { path: 'about', component: AboutComponent }, 
    { path: 'connect', component: ConnectComponent }, 
    { path: 'index', component: LayoutComponent } 
    ]), 
    BrowserModule, 
    FormsModule, 
    HttpModule 
    ], 
    declarations: [ 
    AppComponent, 
    AboutComponent, 
    ConnectComponent, 
    LayoutComponent, 
    HeaderComponent, 
    BreadcrumbComponent, 
    FooterComponent, 
    IndexComponent 
    ], 
    providers: [ ConnectionService, AuthService ], 
    bootstrap: [ AppComponent ] 
}) 
export class AppModule { } 

美女主播與routerLink在有關網頁

<div> 
     <a class="navbar-brand" [routerLink]="['/about']"><i class="fa fa-info"></i></a> 
     <a class="navbar-brand" [routerLink]="['/connect']"><i class="fa fa-plug"></i></a> 
    </div> 

回答

0

更改路由器模塊

{ path: 'about', component: AboutComponent }, 
{ path: 'connect', component: ConnectComponent }, 
{ path: 'index', component: LayoutComponent }, 
{ path: '', redirectTo: 'index', pathMatch: 'full'}, 
{path:'**',redirectTo:'index',pathMatch:'full'} 
+0

已經嘗試過,根本不起作用。 立即啓動無限網址,無需點擊任何routerLink:/ – RickyLeRoi

+0

您可以共享更多代碼或鏈接 –

+0

您認爲哪一部分可能有用? – RickyLeRoi