Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Angular 2中绕过路由器_Javascript_Html_Angular_Angular2 Routing_Angular2 Template - Fatal编程技术网

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 { }