# injectThreadRouting

Package: `@threadplane/angular/chat` · 0.3.7

Reference: /docs/api/angular/chat/injectThreadRouting

```typescript
import { injectThreadRouting } from '@threadplane/angular/chat';
```

## injectThreadRouting · overload 1

Bind an app-owned `activeThreadId` signal to the URL — restore on load, stamp on change,
validate-or-redirect, with a bare URL meaning "no thread" (welcome). URL is the source of
truth; nothing is written to localStorage. Must be called in an injection context.

```typescript
export declare function injectThreadRouting(config: ThreadRoutingConfig): void;
```

```ts
export const ACTIVE_THREAD = signal<string | null>(null);
// app.config.ts, with a LangGraph backend:
// provideAgent({
//   threadId: ACTIVE_THREAD,
//   onThreadId: (id) => ACTIVE_THREAD.set(id),
//   createSession: (context) => createSession({ assistantId, apiUrl, ...context }),
// }),
// provideThreadDirectory({
//   createDirectory: (context) => createLangGraphThreadDirectory({ apiUrl, ...context }),
// }),

// In a component, with `injectThreadDirectory` from `@threadplane/angular`:
const threads = injectThreadDirectory();
injectThreadRouting({
  threadId: ACTIVE_THREAD,
  // `getThread` resolves null for a thread that does not exist.
  validate: (id) => threads.getThread(id).then(Boolean),
});
```