2016-06-22 3 views
0

각도 라우터 구성 요소가 사용되지 않는 베타 버전에서 V3 alpa 0.7로 마이그레이션됩니다.각도 2 라우터 V3 : 제공자 예외 없음

내가 설정을 내

import { provideRouter,RouterConfig } from '@angular/router'; 

//Import components 
import {LoginComponent} from '../auth/component/login.component'; 
import {LogoutComponent} from '../auth/component/logout.component'; 
import {RegisterComponent} from '../auth/component/register.component'; 
import {ForgotpasswordComponent} from '../auth/component /forgotpass.component'; 
import {ResetpasswordComponent} from '../auth/component/resetpass.component'; 

export const routes: RouterConfig = [ 
{path:'user', redirectTo: '/user/login', terminal: true}, 
{path:'user/login', component: LoginComponent}, 
{path:'user/logout', component: LogoutComponent}, 
{path:'user/register', component: RegisterComponent}, 
{path:'user/register/admin', component: RegisterComponent}, 
{path:'user/register/librarytrial', component: RegisterComponent}, 
{path:'user/forgotpass', component: ForgotpasswordComponent}, 
{path:'user/forgotpass/:reset_code', component: ResetpasswordComponent} 
]; 

export const APP_ROUTER_PROVIDERS = [ 
provideRouter(routes) 
]; 

이 작동합니다 아래로하지만 어떤 이유로 그것은 다음과 같은 예외가 발생 main.ts

import {bootstrap} from '@angular/platform-browser-dynamic'; 
import {AppComponent} from './component/app.component'; 
import {HTTP_PROVIDERS} from '@angular/http'; 
import {HttpService} from '../common/service/http.service'; 
import {enableProdMode} from '@angular/core'; 
import {disableDeprecatedForms, provideForms} from '@angular/forms'; 
import {APP_ROUTER_PROVIDERS} from '../routes/auth.routes'; 

enableProdMode(); 

bootstrap(AppComponent,[ 
APP_ROUTER_PROVIDERS, 
HTTP_PROVIDERS, 
HttpService, 
disableDeprecatedForms(), 
provideForms() 
]).catch(err => console.error(err)); 

그리고 auth.routes.ts 다음과 같이 :

platform-browser.umd.js:2311 Error: Uncaught (in promise): No provider for Router! 
at l (zone.min.js:1) 
at zone.min.js:1 
at e.invoke (zone.min.js:1) 
at Object.onInvoke (core.umd.js:9004) 
at e.invoke (zone.min.js:1) 
at e.run (zone.min.js:1) 
at zone.min.js:1 
at e.invokeTask (zone.min.js:1) 
at Object.onInvokeTask (core.umd.js:8995) 
at e.invokeTask (zone.min.js:1) 

네트워크 통화를하면 로그인 구성 요소가 걸리는 것을 알 수 있습니다. user 경로를 입력해야하지만 위의 오류와 함께 템플릿을로드 한 후에 실패합니다. 여기

내가 또한 router-outlet의 주요 구성 요소에 있는지 확인한 로그인 구성 요소

import {Component, OnInit, Input} from '@angular/core'; 
import {FormBuilder,Validators,FormControl,FormGroup,REACTIVE_FORM_DIRECTIVES} from '@angular/forms'; 
import {ROUTER_DIRECTIVES, Router, ActivatedRoute} from '@angular/router'; 
import {ConfigService} from '../../common/service/config.service'; 
import {AuthService} from '../service/auth.service'; 

import {Growl} from 'primeng/primeng'; 
import {Message} from 'primeng/primeng'; 

@Component({ 
    selector: 'login', 
    templateUrl: ConfigService.BASE_URL+'app/auth/views/login.ejs', 
    directives: [ROUTER_DIRECTIVES,REACTIVE_FORM_DIRECTIVES,Growl], 
    providers:[AuthService,FormBuilder] 
}) 

export class LoginComponent implements OnInit{ 

... 

constructor(private _form_builder: FormBuilder, private _auth_service:AuthService, private _router:Router,private _route:ActivatedRoute){ 

    ... 
} 

ngOnInit(){ 

    this._route.params.subscribe(params=>{ 

     this.redirect_to = params['redirect_to']; 

    }); 

} 

} 

의 짧은 버전입니다. 내가 무엇을 놓치고 있습니까?

답변

4

최근 마이그레이션 중에 발생한 오류의 원인 중 하나가 @ angular/router-deprecated를 가져 오는 구성 요소입니다. 앱 구성 요소 또는 로그인으로 중첩 된 다른 구성 요소가 라우터 지원이 중단 된 경우 호출되는지 확인하고, 그렇다면 @ angular/router로 교체하십시오.

+0

이것은 정확하게 나의 경우입니다. 모든 라우터 지원 중단을 제거한 후 작동합니다! –

관련 문제