比如vue-router,可以在多个地方写router hook,比如可以写全局guard,可以per-route写guard,甚至可以在component里写。

那么,在component里写,似乎不错,但一些hook,比如beforeRouteEnter,是不能用到这个component本身的,因为:

The beforeRouteEnter guard does NOT have access to this, because the
guard is called before the navigation is confirmed, thus the new
entering component has not even been created yet.

标签: vue-router

添加新评论