[Angular] Router outlet events

For example, we have a component which just simply render router-outlet:

import { Component } from ‘@angular/core‘;

@Component({
  selector: ‘mail-app‘,
  styleUrls: [‘mail-app.component.scss‘],
  template: `
    <div class="mail">
      <router-outlet></router-outlet>
    </div>
  `
})
export class MailAppComponent {}
export const ROUTES: Routes = [
  { path: ‘folder/:name‘, component: MailFolderComponent }
];

We can add events to router-outlet:

import { Component } from ‘@angular/core‘;

@Component({
  selector: ‘mail-app‘,
  styleUrls: [‘mail-app.component.scss‘],
  template: `
    <div class="mail">
      <router-outlet
        (activate)="onActivate($event)"
        (deactivate)="onDeactivate($event)"
      ></router-outlet>
    </div>
  `
})
export class MailAppComponent {
  onActivate(event) {
    console.log(event)
  }

  onDeactivate(event) {
    console.log(event)
  }
}

When we log out the, we see the actual component been rendered into the router-outlet.

时间: 2025-01-07 11:56:17

[Angular] Router outlet events的相关文章

[从 0 开始的 Angular 生活]No.38 实现一个 Angular Router 切换组件页面(一)

前言 今天是进入公司的第三天,为了能尽快投入项目与成为团队可用的战力,我正在努力啃官方文档学习 Angular 的知识,所以这一篇文章主要是记录我如何阅读官方文档后,实现这个非常基本的.带导航的网页应用. 需求 需求大概是这样的: 开一个新的 Angular 项目,并且一开始选择加入 Router 功能 根组件是 AppComponent ,然后下方有三个子组件分别是 page1 page2 page3 可以在 AppComponent 内点击连结切换到这三个页面 参考文档: 路由与导航 Rou

[Angular] Preserve the current route’s query parameters when navigating with the Angular Router

When we redirect to a different route from within our component's code using the Router.navigate or from within a component template via a [routerLink] directive, we may want to preserve the current route’s query parameters and carry them on to the n

[Angular Router] Lazy loading Module with Auxiliary router

Found the way to handle Auxiliary router for lazy loading moudle and erge load module are different. In Erge loading, it is recommended to create a shell component, inside shell component you need to define the router-outlet for each Auxiliary routes

MVC route 和 Angular router 单页面的一些方式

直接看代码和注释吧 ASP.NET MVC router public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("favicon.ico"); routes.MapMvcAttributeRoutes(); //

[Angular 2] Using events and refs

This lesson shows you how set listen for click events using the (click) syntax. It also covers getting values off of an input using the #ref syntax then passing that value into the onClick event handler.

angular router ui bug !

https://github.com/angular-ui/ui-router/issues/600 https://github.com/angular-ui/ui-router/issues/2229 看完以上的问题,可想是没有结果的! 具体问题: $urlRouterProvider.when("/", "/companys");  被执行时如果有prevent.default 是不可以以加载templateURl的! 避开方法是用template .

[Angular] Adding keyboard events to our control value accessor component

One of the most important thing when building custom form component is adding accessbility support. The component should be focusable. we can achieve this by adding 'tabindex="0"': <div tabindex="0" > Add some css class for foucs

[Angular2 Router] Setup page title with Router events

Article import 'rxjs/add/operator/filter'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/mergeMap'; import { Component, OnInit } from '@angular/core'; import { Router, NavigationEnd, ActivatedRoute } from '@angular/router'; import { Title

[Angular2 Router] Configure Auxiliary Routes in the Angular 2 Router - What is the Difference Towards a Primary Route?

In this tutorial we are going to learn how we can can configure redirects in the angular 2 router configuration. We are also going to see again another example on how the order of the configuration might trip us. We are going to see the different bet