Javascript 如何在Angular 2中绕过路由器
我们有一些模板文件及其组件。他们还定义了自己的路线,并称之为:Javascript 如何在Angular 2中绕过路由器,javascript,html,angular,angular2-routing,angular2-template,Javascript,Html,Angular,Angular2 Routing,Angular2 Template,我们有一些模板文件及其组件。他们还定义了自己的路线,并称之为: <a routerLink="/Path-with-component"> Open page with component </a> 它们总是通过路由器,文件不会从物理路径调用 所以,我们需要他们不要通过角2路由器。我们如何做到这一点?理想情况下,它不应该通过路由器,除非您已经定义了一个通配符路由 { path: '**', component: <some component>} @Co
<a routerLink="/Path-with-component"> Open page with component </a>
它们总是通过路由器,文件不会从物理路径调用
所以,我们需要他们不要通过角2路由器。我们如何做到这一点?理想情况下,它不应该通过路由器,除非您已经定义了一个通配符路由
{ 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 { }
检查这个
希望这有帮助 在路径href=/Static-page.html之前添加反斜杠
{ 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 { }