以下の内容はhttps://maitakeramen.hatenablog.com/entry/2022/08/17/180128より取得しました。


【Angular】ページリロードや直リンクされたときに強制的にトップページに戻す方法

方法

app.component.ts のコンストラクターでトップページのURLに遷移する処理を書いてあげれば良いです。
実際のコードは下記になります。

app.component.ts

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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'TestApplication';
  constructor(private router: Router) {
    this.router.navigateByUrl('/');
  }
}

説明

this.router.navigateByUrl('/');
によって、URLをルートに遷移させています。
リロードや直リンクの場合、サービスやストアに値は何も残っていないはずなので、必ずトップページに戻ります。




以上の内容はhttps://maitakeramen.hatenablog.com/entry/2022/08/17/180128より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14