0

구성 요소가있는 템플릿 파일이 몇 가지 있습니다. 우리는 또한 엄격히 같은 논리를 필요로하지 않는다 일반 및 정적.html 파일이각도 2로 라우터를 우회하는 방법

<a routerLink="/Path-with-component"> Open page with component </a> 

: 그들은 또한 자신의 경로가 정의처럼라고합니다. 그래서 우리는 그들을 다음과 같이 부르고 있습니다.

그들은 항상 라우터를 통과하며 파일은 실제 경로에서 호출되지 않습니다.

따라서 Angular 2 라우터를 통과하지 않아야합니다. 어떻게해야합니까?

+1

''href = "/ Static-page.html"''경로 앞에 백 슬래시 추가 –

답변

1

와일드 카드 경로를 정의하지 않은 이상 이상적으로 라우터를 통과해서는 안됩니다.

{ path: '**', component: <some component>} 

@Component({ 
    selector: 'my-app', 
    template: `<h1>Hello {{name}}</h1> 
    <hr /> 
    <a routerLink="/home" >Home</a> 
    <a href='test.html' >Static page</a> 
    <hr /> 
    <router-outlet></router-outlet> 
    ` 
}) 
class AppComponent { name = 'Angular'; } 

@Component({ 
    template: `<h1>Home</h1> 
    ` 
}) 
class HomeComponent { } 

const appRoutes: Routes = [ 
    { path: '', redirectTo: '/home', pathMatch: 'full' }, 
    { path: 'home', component: HomeComponent } 
]; 

@NgModule({ 
    imports:  [ BrowserModule, RouterModule.forRoot(appRoutes) ], 
    declarations: [ AppComponent, HomeComponent ], 
    bootstrap: [ AppComponent ] 
}) 
export class AppModule { } 

확인이 도움이 Plunker

희망을!