deepthan/blog-angular

Angular 获取当前路由

deepthan opened this issue · 0 comments

获取当前路由

import { ActivatedRoute, Router } from '@angular/router';

export class xxxx {
    constructor(
        private activatedRoute: ActivatedRoute,
        private router: Router
    ){
        // 获取当前路由地址path: this.router.url
        conosle.log(this.router.url)
    
        // 获取当前路由的其他数据
        this.activatedRoute.data.subscribe(res => console.log(res));
    }
}