mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-06-11 02:33:10 +08:00
Translated 85 skill sub-reference files to achieve full parity with the English source: - skills/angular-developer/references/ — 35 files (all references) - skills/remotion-video-creation/rules/ — 28 files (all rules) - skills/tinystruct-patterns/references/ — 5 files - skills/openclaw-persona-forge/references/ — 6 files - skills/skill-comply/prompts/ — 3 files - skills/lead-intelligence/agents/ — 4 files - skills/brand-voice/references/ — 1 file - skills/frontend-slides/ — 2 files - hooks/memory-persistence/README.md — 1 file English source parity: 0 missing files (excluding rules/zh/, internal docs, and experimental examples absent from zh-CN)
53 lines
1.8 KiB
Markdown
53 lines
1.8 KiB
Markdown
# ルートガード
|
||
|
||
ルートガードは、ユーザーがルートへ遷移できるか、またはルートから離れられるかを制御します。
|
||
|
||
## ガードの種類
|
||
|
||
- **`CanActivate`**:ユーザーはこのルートにアクセスできるか?(例:認証チェック)
|
||
- **`CanActivateChild`**:ユーザーはこのルートの子にアクセスできるか?
|
||
- **`CanDeactivate`**:ユーザーはこのルートから離れられるか?(例:未保存の変更)
|
||
- **`CanMatch`**:このルートはマッチングの対象として考慮すべきか?(例:フィーチャーフラグ)`false` を返すと、ルーターは他のルートのチェックを継続します。
|
||
|
||
## ガードの作成
|
||
|
||
Angular 15 以降、ガードは通常、関数として定義します。
|
||
|
||
```ts
|
||
export const authGuard: CanActivateFn = (route, state) => {
|
||
const authService = inject(AuthService);
|
||
const router = inject(Router);
|
||
|
||
if (authService.isLoggedIn()) {
|
||
return true;
|
||
}
|
||
|
||
// ログインページへリダイレクト
|
||
return router.parseUrl('/login');
|
||
};
|
||
```
|
||
|
||
## ガードの適用
|
||
|
||
ルート設定に配列として追加します。順番通りに実行されます。
|
||
|
||
```ts
|
||
{
|
||
path: 'admin',
|
||
component: Admin,
|
||
canActivate: [authGuard],
|
||
canActivateChild: [adminChildGuard],
|
||
canDeactivate: [unsavedChangesGuard]
|
||
}
|
||
```
|
||
|
||
## 戻り値
|
||
|
||
- `boolean`:`true` で許可、`false` でブロック。
|
||
- `UrlTree` または `RedirectCommand`:別のルートへリダイレクト。
|
||
- `Observable` または `Promise`:上記の型に解決されます。
|
||
|
||
## セキュリティに関する注意
|
||
|
||
**クライアントサイドのガードはサーバーサイドのセキュリティの代わりにはなりません。** サーバー側で常に権限を検証してください。
|