通过routerLink定位指定的插座增加了无关的" /"

时间:2017-02-07 15:49:00

标签: angular modal-dialog angular2-routing router outlet

我试图通过路由在我的应用中启动模式。一切似乎都有效,除了向URL添加额外的斜杠以防止它解析。网址应如下所示(如果我手动输入,则会有效)...

/accounts(modal:accounts/1/edit)

但是我得到了这个(注意基本网址和出口目标之间的斜线)......

/accounts/(modal:accounts/1/edit)

基础标签已设置...

<head>
  <meta charset="utf-8">
  <title>myApp</title>
  <base href="/">
  ...
</head>

这是我的路由配置(accounts-routing.module.ts)

const ACCOUNT_ROUTES: Routes = [
  {
    path: 'accounts',
    component: AccountsIndexComponent
  },{
    path: 'accounts/new',
    component: AccountsNewComponent
  },{
    path: 'accounts/:id',
    component: AccountsShowComponent
  },{
    path: 'accounts/:id/edit',
    component: AccountsEditComponent,
    outlet: 'modal'
  }
];

和outlet(app.component.html)

<router-outlet></router-outlet>
<router-outlet name="modal"></router-outlet>

链接......

<a [routerLink]="[{ outlets: { modal: ['accounts', account.id, 'edit'] } }]">Edit</a>

我错过了什么?该项目是使用angular-cli@1.0.0-beta.26创建的,angular@2.4.6angular-router@3.4.6已安装。

FWIW,这是日志的屏幕截图......

failed routing attempt

1 个答案:

答案 0 :(得分:25)

修复是在链接上定义一个空的相对路径。感谢@unitario指出我正确的方向!

<a [routerLink]="['', { outlets: { modal: ['accounts', account.id, 'edit'] } }]">Edit</a>