Skip to content

Latest commit

 

History

History
68 lines (40 loc) · 1.62 KB

router-instance.md

File metadata and controls

68 lines (40 loc) · 1.62 KB

Router 实例

属性

router.app

  • 类型: Vue instance

    配置了 router 的 Vue 根实例。

router.mode

  • 类型: string

    路由使用的 模式

router.currentRoute

方法

  • router.beforeEach(guard)

  • router.beforeResolve(guard) (2.5.0+): 此时异步组件已经加载完成

  • router.afterEach(hook)

    增加全局的导航钩子。参考 导航钩子.

  • router.push(location, onComplete?, onAbort?)

  • router.replace(location, onComplete?, onAbort?)

  • router.go(n)

  • router.back()

  • router.forward()

    动态的导航到一个新 url。参考 编程式导航.

  • router.getMatchedComponents(location?)

    返回目标位置或是当前路由匹配的组件数组(是数组的定义/构造类,不是实例)。通常在服务端渲染的数据预加载时时候。

  • router.resolve(location, current?, append?)

    2.1.0+

    解析目标位置(格式和 <router-link>to prop 一样),返回包含如下属性的对象:

    {
      location: Location;
      route: Route;
      href: string;
    }
  • router.addRoutes(routes)

    2.2.0+

    动态添加更多的路由规则。参数必须是一个符合 routes 选项要求的数组。

  • router.onReady(callback)

    2.2.0+

    添加一个会在第一次路由跳转完成时被调用的回调函数。此方法通常用于等待异步的导航钩子完成,比如在进行服务端渲染的时候。