angular2里默認切換路由或者切換組件,頁面的title是不會變化的。
angular2在路由設置里提供了data參數可以傳值,如下
{ path: 'home', component: HomeComponent, data: { title: 'Home', aaa: 'aaaa', bbb: 'bbbb', ccc: "cccc"} }
path和component是常用的屬性,path是地址欄的顯示,component是調用的組件。
data則可以傳數據,在組件內可以調用。
參數調用
angular2提供Title服務可以修改title。
路由內獲取設置的參數可以用ActivatedRoute的snapshot的data屬性獲取
如下:
import { ActivatedRoute } from '@angular/router'; import { Title } from '@angular/platform-browser'; config: any; constructor( private route: ActivatedRoute, private titleService: Title ) { } ngOnInit(): void { // Get the config information from the app routing data this.config = this.route.snapshot.data; // Sets the page title this.titleService.setTitle(this.config.title); }
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com