2017-02-22 223 views
1

我有問題,如果我用應顯示特定組件的url重新加載我的應用程序,我的應用程序將顯示默認頁面。例如,我想直接通過瀏覽器(刷新)訪問/創建/用戶,他將顯示我的默認頁面。更新角度後路由器不會路由到組件2

這是我的路由配置。

import {provideRouter, RouterConfig} from '@angular/router'; 
import {GenericRequestEndpoint} from './components/dynamicresponsetable/dynamicresponsetable.component'; 
import {DynamicDisplayForm} from './components/dynamicdisplaycomponent/dynamic.display.component'; 
import {DynamicCreationComponent} from './components/dynamiccreationcomponent/dynamic.creation.component'; 
import {LoginComponent} from './components/login/login.component'; 
import {AuthService} from './components/services/auth.service'; 
import {AuthGuard} from './components/services/auth-guard.service'; 
import {Dummy} from './components/dummy'; 
import {ConfigurationComponent} from './components/configurationcomponent/configuration.component'; 


export const ROUTER: RouterConfig = [ 
    { 
     path: '', 
     component: LoginComponent 
    }, 
    { 
     path: 'dashboard', 
     component: Dummy, 
     canActivate: [AuthGuard] 
    }, 
    { 
     path: 'endpoint/:endpointname', 
     component: GenericRequestEndpoint, 
     canActivate: [AuthGuard] 
    }, 
    { 
     path: 'detail/:specificitem', 
     component: DynamicDisplayForm, 
     canActivate: [AuthGuard] 
    }, 
    { 
     path: 'create/:endpointname', 
     component: DynamicCreationComponent, 
     canActivate: [AuthGuard] 
    }, 
    { 
     path: 'configurator/:endpointname', 
     component: ConfigurationComponent, 
     canActivate: [AuthGuard] 
    } 
]; 



export const APP_ROUTER_PROVIDERS = [ 
    provideRouter(ROUTER), AuthService, AuthGuard 
]; 

回答

1

如果使用空路徑'',沒有孩子的路線,再加入pathMatch

{ 
    path: '', 
    component: LoginComponent, 
    pathMatch: 'full' 
}, 
+0

它沒有工作。也許我必須舉一個更好的例子。設想一個用戶發送一個鏈接給另一個用戶。例如http:// localhost:3000/create/user。現在我的問題是Angular沒有重定向到我的DynamicCreationComponent。路由器只是空的。 –

+0

你使用什麼服務器?這是發生在'ng服務'嗎? –

+0

你的意思是什麼「路由器只是空的」? –