Angular路由器导航重新初始化组件
创始人
2024-10-28 03:00:27
0

在Angular中,可以使用Router.navigate方法来导航到同一个路由,并通过设置{ skipLocationChange: true }来重新初始化组件。以下是一个示例代码:

HTML模板:


组件代码:

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-your-component',
  templateUrl: './your-component.component.html',
  styleUrls: ['./your-component.component.css']
})
export class YourComponentComponent implements OnInit {

  constructor(private router: Router) { }

  ngOnInit(): void {
    // 在组件初始化时执行的操作
  }

  reloadComponent() {
    this.router.navigate(['/your-route'], { skipLocationChange: true }).then(() => {
      this.router.navigate(['/your-component']);
    });
  }

}

在上述示例中,当用户点击"重新初始化组件"按钮时,reloadComponent方法会通过Router.navigate重新导航到同一个路由'/your-component',并通过{ skipLocationChange: true }来跳过URL的更改,从而重新初始化组件。

相关内容

热门资讯

透视好友房"线上德州... 透视好友房"线上德州的辅助器是什么"详细辅助技巧教程(免费透视脚本方法)是一款可以让一直输的玩家,快...
透视存在"pokem... 透视存在"pokemmo手机脚本辅助器"详细辅助技巧教程(私人局可以玩教程)是一款可以让一直输的玩家...
辅助透视"hhpko... 辅助透视"hhpkoer辅助挂是真的吗"详细辅助辅助教程(辅助软件教程神器);亲真的是有正版授权,小...
透视规律"epoke... 《透视规律"epoker底牌透视"详细辅助攻略教程(透视挂底牌方法)》 epoker底牌透视软件透明...
透视规律"werpl... 透视规律"werplan外挂"详细辅助必胜教程(破解辅助插件教程);1分钟了解详细教程(微信 136...
透视规律"德普之星a... 透视规律"德普之星app安卓版破解版"详细辅助揭秘攻略(俱乐部辅助器软件);1分钟了解详细教程(微信...
透视美元局"wepo... 透视美元局"wepoker破解器有用吗"详细辅助解说技巧(私人局透视方法辅助);大神普及一款德州ai...
透视了解"hhpok... 透视了解"hhpoker德州机器人"详细辅助可靠技巧(有人用过技巧)1、点击下载安装,微扑克wpk插...
透视实锤"德普之星有... 透视实锤"德普之星有透视辅助吗"详细辅助微扑克教程(免费透视脚本攻略)是一款可以让一直输的玩家,快速...
透视工具"hhpok... 透视工具"hhpoker透视脚本"详细辅助爆料教程(祈福有用攻略);小薇(透视辅助)致您一封信;亲爱...