zodream梦想开源/个人编程日记

zodream梦想开源/个人编程日记

简单的个人编程日记

马上订阅 zodream梦想开源/个人编程日记 RSS 更新: https://zodream.cn/blog/rss

angular9教程之监听子路由变化

2020年5月17日 06:14
编程技术

需求

根据下级路由改变父组件的菜单选中

解决方法

主要通过 this.router.events.subscribe 获取路由的变化

export class FrontendComponent {
    constructor(
        private router: Router) {
        this.router.events.subscribe(event => {
            if (event instanceof NavigationEnd) {
                // event.url  '/blog'
                this.routerChanged(event.url);
            }
        });
    }
}

获取当前路由网址进行切换