ルートガード は、ルートへの/からのナビゲーションが許可されるかどうかを制御する 関数です。ルートがアクティブになる前(またはルートを離れる前)に実行され、認証チェック、権限制御、「保存されていない変更」プロンプトを実現します。
ガードの種類
text
CanActivate → can the user enter this route? (auth/permission check)
CanActivateChild → same, for child routes
CanDeactivate → can the user LEAVE? ("you have unsaved changes")
CanMatch → should this route even be matched? (feature flags, role-based)
resolve → pre-fetch data BEFORE the route activates
関数型 CanActivate ガード(モダン Angular)
ts
