# route selection

Source: docs/source/exhibits/guides/typesafe-router/route-selection.ts

```ts
import type { AtomToken } from "atom.io"
import { selector } from "atom.io"

import { pathnameAtom } from "./pathname-state.ts"
import { isRoute, type Route } from "./route-shape.ts"

declare const authAtom: AtomToken<boolean | null>
declare function isPublicRoute(path: Route): boolean

export const routeSelector = selector<Route | 404>({
	key: `route`,
	get: ({ get }) => {
		const pathname = get(pathnameAtom)
		const path = pathname.split(`/`).slice(1).filter(Boolean)

		if (!isRoute(path)) {
			return 404
		}

		if (isPublicRoute(path)) {
			return path
		}

		const auth = get(authAtom)
		if (!auth) {
			return [`login`]
		}

		if (path.length === 0) {
			return [`docs`]
		}

		return path
	},
})
```
