ActivatedRouteSnapshot

ActivatedRouteSnapshot

Stable Interface

What it does

Contains the information about a route associated with a component loaded in an outlet at a particular moment in time. ActivatedRouteSnapshot can also be used to traverse the router state tree.

How to use

@Component({templateUrl:'./my-component.html'})
class MyComponent {
  constructor(route: ActivatedRoute) {
    const id: string = route.snapshot.params.id;
    const url: string = route.snapshot.url.join('');
    const user = route.snapshot.data.user;
  }
}

Interface Overview

interface ActivatedRouteSnapshot {
  url : UrlSegment[]
  params : Params
  queryParams : Params
  fragment : string
  data : Data
  outlet : string
  component : Type<any>|string
  routeConfig : Route
  root : ActivatedRouteSnapshot
  parent : ActivatedRouteSnapshot
  firstChild : ActivatedRouteSnapshot
  children : ActivatedRouteSnapshot[]
  pathFromRoot : ActivatedRouteSnapshot[]
  paramMap : ParamMap
  queryParamMap : ParamMap
  toString() : string
}

Interface Description

Interface Details

url : UrlSegment[]

The URL segments matched by this route

params : Params

The matrix parameters scoped to this route

queryParams : Params

The query parameters shared by all the routes

fragment : string

The URL fragment shared by all the routes

data : Data

The static and resolved data of this route

outlet : string

The outlet name of the route

component : Type<any>|string

The component of the route

routeConfig : Route

The configuration used to match this route

root : ActivatedRouteSnapshot

The root of the router state

parent : ActivatedRouteSnapshot

The parent of this route in the router state tree

firstChild : ActivatedRouteSnapshot

The first child of this route in the router state tree

children : ActivatedRouteSnapshot[]

The children of this route in the router state tree

pathFromRoot : ActivatedRouteSnapshot[]

The path from the root of the router state tree to this route

paramMap : ParamMap
queryParamMap : ParamMap
toString() : string

exported from router-index, defined in router/src/router_state.ts

© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/docs/ts/latest/api/router/index/ActivatedRouteSnapshot-interface.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部