# switchLink

> Pick one of several named chains per call, and let a call force one with a typed call option.

`switchLink({ name, links, pick })` sends each call down one of several named branches. `pick` chooses the branch for a call, and `name` becomes a typed call option, so one call can override `pick`:

```ts
const client = createTrpcClient({
  router: routerType<AppRouter>(),
  links: [
    switchLink({
      name: 'transport',
      links: {
        http: httpLink({ url, batch: true }),
        ws: wsLink({ url: wsUrl }),
      },
      pick: (op) => (op.type === 'subscription' ? 'ws' : 'http'),
    }),
  ],
});
await client.report.query(input, { transport: 'http' });
```

A branch can be a chain (an array of links), including another `switchLink`. On a client made with `router:`, `pick` sees typed paths.

The name can't be `signal`, `lastEventId`, `init`, `headers` or `reconnect`, and two switch links on one chain can't share a name; both are type errors and throw when the link is made.

Like [`splitLink`](https://v12.trpc.io/docs/client/links/split.md), calls get the call options and errors of every branch's links ([Custom links](https://v12.trpc.io/docs/client/custom-links.md#branching-links)).
