方法
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をルートに遷移させています。
リロードや直リンクの場合、サービスやストアに値は何も残っていないはずなので、必ずトップページに戻ります。