From c452e56a4e1854907bb432c2dce6bd6a960bf469 Mon Sep 17 00:00:00 2001 From: zhaoss Date: Wed, 20 Apr 2022 16:18:33 +0800 Subject: [PATCH] =?UTF-8?q?2.2.9=E5=B0=8F=E8=8A=82=E4=B9=A0=E9=A2=98?= =?UTF-8?q?=E3=80=81=E5=85=B3=E9=94=AE=E5=AD=97=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config.json" | 10 ++++ .../exercises.json" | 7 +++ .../exercises.md" | 60 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 "data/2.Vue\344\270\255\351\230\266/2.Vue-router/9.\345\220\216\347\275\256\350\267\257\347\224\261\345\256\210\345\215\253/config.json" create mode 100644 "data/2.Vue\344\270\255\351\230\266/2.Vue-router/9.\345\220\216\347\275\256\350\267\257\347\224\261\345\256\210\345\215\253/exercises.json" create mode 100644 "data/2.Vue\344\270\255\351\230\266/2.Vue-router/9.\345\220\216\347\275\256\350\267\257\347\224\261\345\256\210\345\215\253/exercises.md" diff --git "a/data/2.Vue\344\270\255\351\230\266/2.Vue-router/9.\345\220\216\347\275\256\350\267\257\347\224\261\345\256\210\345\215\253/config.json" "b/data/2.Vue\344\270\255\351\230\266/2.Vue-router/9.\345\220\216\347\275\256\350\267\257\347\224\261\345\256\210\345\215\253/config.json" new file mode 100644 index 0000000..dc70abc --- /dev/null +++ "b/data/2.Vue\344\270\255\351\230\266/2.Vue-router/9.\345\220\216\347\275\256\350\267\257\347\224\261\345\256\210\345\215\253/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "vue-c6f3a75adadc4901a88a307fb1ee2f07", + "keywords": [], + "children": [], + "export": [ + "exercises.json" + ], + "keywords_must": [], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.Vue\344\270\255\351\230\266/2.Vue-router/9.\345\220\216\347\275\256\350\267\257\347\224\261\345\256\210\345\215\253/exercises.json" "b/data/2.Vue\344\270\255\351\230\266/2.Vue-router/9.\345\220\216\347\275\256\350\267\257\347\224\261\345\256\210\345\215\253/exercises.json" new file mode 100644 index 0000000..fd8e14d --- /dev/null +++ "b/data/2.Vue\344\270\255\351\230\266/2.Vue-router/9.\345\220\216\347\275\256\350\267\257\347\224\261\345\256\210\345\215\253/exercises.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": null, + "source": "exercises.md", + "notebook_enable": false, + "exercise_id": "fb46478694144ee787c0f1f66f3118f5" +} \ No newline at end of file diff --git "a/data/2.Vue\344\270\255\351\230\266/2.Vue-router/9.\345\220\216\347\275\256\350\267\257\347\224\261\345\256\210\345\215\253/exercises.md" "b/data/2.Vue\344\270\255\351\230\266/2.Vue-router/9.\345\220\216\347\275\256\350\267\257\347\224\261\345\256\210\345\215\253/exercises.md" new file mode 100644 index 0000000..7bd63f3 --- /dev/null +++ "b/data/2.Vue\344\270\255\351\230\266/2.Vue-router/9.\345\220\216\347\275\256\350\267\257\347\224\261\345\256\210\345\215\253/exercises.md" @@ -0,0 +1,60 @@ +# 后置路由守卫 + +
小常识:
+
+ +**全局后置钩子** +你也可以注册全局后置钩子,然而和守卫不同的是,这些钩子不会接受 next 函数也不会改变导航本身: + +```javascript +router.afterEach((to, from) => { + sendToAnalytics(to.fullPath) +}) +``` + +它们对于分析、更改页面标题、声明页面等辅助功能以及许多其他事情都很有用。 + +它们也反映了 navigation failures 作为第三个参数: + +```javascript +router.afterEach((to, from, failure) => { + if (!failure) sendToAnalytics(to.fullPath) +}) +``` +**完整的导航解析流程** +导航被触发。 +在失活的组件里调用 beforeRouteLeave 守卫。 +调用全局的 beforeEach 守卫。 +在重用的组件里调用 beforeRouteUpdate 守卫(2.2+)。 +在路由配置里调用 beforeEnter。 +解析异步路由组件。 +在被激活的组件里调用 beforeRouteEnter。 +调用全局的 beforeResolve 守卫(2.5+)。 +导航被确认。 +调用全局的 afterEach 钩子。 +触发 DOM 更新。 +调用 beforeRouteEnter 守卫中传给 next 的回调函数,创建好的组件实例会作为回调函数的参数传入。 +
+ +
小测试:
+ + +根据上方资料,以下关于后置路由守卫的说法不正确的是?

+ +## 答案 + +router.afterEach 接受next参数 + +## 选项 + +### A + +不会改变导航本身 + +### B + +接受navigation failures 作为第三个参数 + +### C + +后置路由守卫是异步解析执行,此时导航在所有守卫 resolve 完之前一直处于等待中 -- GitLab