` }) export class MyComponent { currentPath: string; constructor(private route: ActivatedRoute) { this.currentPath = this.getCurrentPath(); } getCurrentPath(): string { const pathFromRoot = this.route.pathFromRoot.map(route => route.routeConfig?.path); return pathFromRoot.join('/'); ...
name ='Get Current Url Route Demo';currentRoute:string;constructor(privaterouter: Router){console.log(router.url); router.events.filter(event=>eventinstanceofNavigationEnd) .subscribe(event=>{this.currentRoute= event.url;console.log(event); }); } } I have created a variable calledcurrentRoute,...
path: "xxxx" __proto__: Object length: 1 __proto__: Array(0) */ this.route.parent.url.subscribe(url => console.log(url[0].path)); // Get Current Path: company 同理 this.route.url.subscribe(url => console.log(url[0].path)); // Route Data: { title: 'Company' } this.rou...
}) export class CompanyComponent implements OnInit { constructor( private router: Router, private route: ActivatedRoute ) {} ngOnInit() { // Parent: about this.route.parent.url.subscribe(url => console.log(url[0].path)); // Current Path: company this.route.url.subscribe(url => console....
angular 的 router 有一个原则, 如果你触发一个 或则调用 router.navigate(...) 但是最终它发现 url 没变动,那么什么不会发生, route event 统统没有运行. 还有另一个是当 url change 时 angular 不会轻易 rebuild component, 如果它的 path 依然是激活的 angular 会保留它哦. 更新: 2017...
/pro/1 切换到/pro/1221 clickDown() { this.router.navigateByUrl('/pro/1221'); this.router.routeReuseStrategy.shouldReuseRoute = function(){ return false; }; } 我们发现生命周期会重新执行 Route 定义单个路由的配置对象 通配符 无论你导航到何处,来执行实例化的组件 js [{ path: '**', compone...
'ngResource','ngCookies']).run(function($rootScope,$location,Auth){// Redirect to login if route requires auth and you're not logged in$rootScope.$on('$routeChangeStart',function(event,next){Auth.isLoggedInAsync(function(loggedIn){if(next.authenticate&&!loggedIn){$location.path('/');}}...
`pathMatch` will likely need to be updated to have an explicit `Route`/`Routes` type so that TypeScript does not infer the type as `string`. - When returning a `Promise` from the `LoadChildrenCallback`, the possible type is now restricted to ...
ngx-route-manager - A simple library to store all route urls used in the application. ng-whiteboard - Lightweight Angular whiteboard component. ngs-json-utils - A lightweight utility library for Angular applications that provides easy-to-use functions for working with JSON objects. It includes ...
.map(route => { while (route.firstChild) route = route.firstChild; return route; }) .subscribe((event) => { console.log('NavigationEnd:', event); }); this.router.events .filter(event => event instanceof NavigationEnd) .map(() => this.activatedRoute) ...