Route guards คือฟังก์ชันที่ควบคุมว่าการนำทางไปยัง/จากเส้นทางได้รับอนุญาตหรือไม่ ฟังก์ชันเหล่านี้ทำงานก่อนที่เส้นทางจะเปิดใช้งาน (หรือก่อนที่คุณจะออกจากเส้นทาง) ซึ่งช่วยให้การตรวจสอบการพิสูจน์ตัวตน การควบคุมสิทธิ์ และข้อความเตือน "มีการเปลี่ยนแปลงที่ยังไม่บันทึก"
ประเภทของ guard
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
