0

いくつかのテンプレートファイルがあります。我々はまた、厳密などの任意のロジックを必要としない平野と静的.htmlファイルを持っている角度2のルータをバイパスする方法

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

:彼らはまた、ルートが定義されており、同様に呼ばれています。したがって、私たちは次のように呼んでいます:

<a href="Static-page.html">Open static page</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

をチェック!

関連する問題