2017-09-13 34 views
1

我有一個有很多路由的角4應用程序。 我的問題很容易理解。所有路由在應用內都可以正常工作。 當我直接去到一個特定的網址時,問題就出來了 Ex。 基本的網址應用程序是http://myserver/ 當我調用上述網址時,我看到我的主頁(http://myserver/home) 如果我調用特定路徑的網址(例如http://myserver/anotherpathpage),應用程序會將我重定向到家中。當調用直接url路徑時,角4路由不起作用

有什麼想法? 我使用HTML5的定位策略(url中沒有哈希)和我的基本href是「/」

非常感謝 ˚F

+0

問題似乎無論何時去具體路徑(例如:http:// myserver/anotherpathpage),總是重定向到主頁?此外,預期的結果顯示特定的頁面內容? – NguaCon

+0

是的,這是我的問題。當我調用特定路徑或重新加載頁面時,請始終進入主頁 –

回答

0

你可以嘗試配置類似的東西:

import { NgModule } from '@angular/core'; 
import { Routes, RouterModule } from '@angular/router'; 

const routes: Routes = [ 
    { path: '', redirectTo: '/home', pathMatch: 'full'}, 
    { 
     path: '', loadChildren: './layout/layout.module#LayoutModule' 
    }, 
    { path: 'home', loadChildren: './home/home.module#HomeModule' }, 
    { path: '**', redirectTo: 'not-found' } 
]; 

@NgModule({ 
    imports: [RouterModule.forRoot(routes, {useHash: false})], 
    exports: [RouterModule] 
}) 
export class AppRoutingModule { } 

使用pathMatch:'full'僅限制應重定向到主頁的根路徑。其他路徑將由佈局模塊路由。

我希望能幫到你。