2017-10-19 6 views
0

私の子供ルートのbeforeEnterガードを定義しようとしていますが、成功しません。ここに私のルートの設定です:私はページを更新したり(例:BASE_PATH /パス2)をブラウザにURLを直接挿入するとVue-router:beforeEnterガードが子パスに対して正しく動作しない

... 
    { 
    path: '/', 
    component: App 
    beforeEnter: (to, from, next) -> 
     # This block is only reached when I refresh the page 

    children: [ 
     { 
     name: 'component1', 
     path: '/component1', 
     components: component1 
     }, 
     { 
     name: 'path2', 
     path: '/path2', 
     components: component2 
     }, 
    ... 
    ] 
    } 
    ... 

すべてが正常に動作します。しかし、path1またはpath2にリダイレクトするルータリンクをクリックすると、beforeEnterガードは実行されません。

私は間違ったことを理解しましたか?各子供にbeforeEnterガードを設定する必要がありますか?

答えて

0

最適なソリューションを追加してください。

beforeEnterはルートガードごとに適用され、親ルートのみに適用されていましたが、子ルートには適用されませんでした。

0

beforeRouteUpdateフック、私が代わりにbeforeEnterのbeforeEachガードを使用することがわかった、すなわち

... 
{ 
path: '/', 
component: App 
beforeEnter: (to, from, next) -> 
    # This block is only reached when I refresh the page 
beforeRouteUpdate: (to, from, next) -> 
    # This will called when you use router-links 
children: [ 
    { 
    name: 'component1', 
    path: '/component1', 
    components: component1 
    }, 
    { 
    name: 'path2', 
    path: '/path2', 
    components: component2 
    }, 
... 
] 
} 
... 
関連する問題