2017-02-07 8 views
8

ルーティング経由で私のアプリケーションでモーダルを起動しようとしています。 URLに余分なスラッシュが追加され、解決できないという点を除いて、すべて機能しているようです。 URLは次のようになります(と私はそれを手動で入力した場合、それは動作します)...routerLink経由で名前付きコンセントをターゲットにすると、余分な "/"が追加される

/accounts(modal:accounts/1/edit) 

しかし、私は...これは代わりに、(ベースURLと出口ターゲット間のスラッシュに注意してください)

を取得しています ベースタグが設定されている
/accounts/(modal:accounts/1/edit) 

...

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

はここに私のルーティングの設定です(アカウント-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' 
    } 
]; 

と出口(app.component.html)

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

そしてリンク...

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

私は何をしないのですか?プロジェクトは[email protected]を使用して作成され、[email protected]および[email protected]がインストールされています。

FWIWは、ここでの修正は、リンク上の空の相対パスを定義することでした

failed routing attempt

+0

''を 'index.html'ファイルに追加しましたか? – unitario

+0

ええ、 ''タグがあります – Brian

+0

''タグの最初の子は?あなたの問題は、関連するパスがどのように解決されたかであろうと思う。 – unitario

答えて

17

...ログのスクリーンショットです。正しい方向に私を向けるための@unitarioに感謝します!

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

In our application we have an authentication modal that can open over any view so any initial path caused issues, either by loosing the current route or by adding extra slash. This solved the issue, Thank you! the only thing added is queryParamsHandling="merge" to facilitate passing parameters to the modal and the underlying view '' – Greg

関連する問題