내 angular2 앱에서 리디렉션 경로를 만들려고합니다.Angular2 리디렉션 경로가 브라우저 URL을 변경하지 않습니다.
하지만 내 문제는 누군가가 다음 사용자가 'HomeComponent'로 재 'nopath'하지만 URL이 여전히 '/ #/nopath'
을 유지 같은 잘못된 경로를 입력 할 때 나는에 redirectTo 경로를 원하는 것입니다 너무 url을 바꾸십시오! 어떻게해야합니까?
내 HomeComponent 생성자에 if를 넣어 현재 URL을 확인하고 homecomponent로 경로를 변경해야합니까? 아니면 제가 빠진 것이 있습니까?
경로 :
const routes: Routes = [
{ path: '', pathMatch: 'full', component: HomeComponent },
{ path: 'login', component: LoginComponent, canActivate: [AnonymousGuard] },
{ path: 'register', component: RegisterComponent, canActivate: [AnonymousGuard] },
{ path: 'users', component: UserComponent, canActivate: [AuthGuard] },
{ path: '**', redirectTo: '' }
];
export const routing: ModuleWithProviders = RouterModule.forRoot(routes, {useHash: true});
편집 :
이를 시도,하지만 난 홈 구성 요소
const routes: Routes = [
{ path: '', pathMatch: 'full' , redirectTo: 'home' },
{ path: 'home', component: HomeComponent },
{ path: 'login', component: LoginComponent, canActivate: [AnonymousGuard] },
{ path: 'register', component: RegisterComponent, canActivate: [AnonymousGuard] },
{ path: 'users', component: UserComponent, canActivate: [AuthGuard] },
{ path: '**', redirectTo: '' }
];
리디렉션 경로를 사용하지 않고 "**", component : HomeComponent (리디렉션 대신)를 사용하십시오. (NM은 두 가지 방법으로 시도했다. 그래, 나는 이것을하지 않을 것이다). –
최신 Angular2 및 라우터 버전을 사용하고 있습니까? 최근에 비슷한 문제가 발생하여 업데이트가 해결 된 것을 보았습니다. –
라우터의 3.2.3 버전을 사용합니다. 최신 버전이 있는지 확인하는 방법을 모르겠습니다. – Vince