effector / effector/router

routeNotFound option in createRouter

Open
#64 0 comments 0 reactions 0 assignees View on GitHub
atomic-router feature parity enhancement scope:core
Dominant language
TypeScript
Stars
8
Forks
2
Avg merge
13h 44m
Merged PRs (30d)
1

Description

### Problem

There is no core-level 404 primitive. `createRoutesView({ otherwise })` only covers rendering a fallback in React — there is no effector unit to drive logic (redirect to /404, analytics, SSR 404 status). atomic-router provides `notFoundRoute` + `routeNotFound` for this.

### Proposed solution

Accept a **pathless route** in `createRouter` config:

```ts
const notFoundRoute = createRoute(); // pathless

const router = createRouter({
routes: [...],
routeNotFound: notFoundRoute, // PathlessRoute, optional
});
```

When a location update matches zero routes, the router opens it internally (via `internal.navigated` with `navigate: false` — no history write); when a match appears, it closes it. Since it is a regular route, the full contract comes for free: `$isOpened`, `opened`/`openedOnServer`/`openedOnClient`/`closed`, and it plugs directly into `createRoutesView`, `chainRoute`, `redirect`. Type- and runtime-restricted to pathless routes (`is.pathlessRoute`).

### Alternatives considered

Derived `$activeRoutes.map((r) => r.length === 0)` — gives a boolean but no events and no route to bind views/chains to; a bare `notFound` event — weaker, "everything is a route" is more consistent.

### Package

`@effector/router` (core)

Contributor guide

Open the contributing guide

Research direction

Start at the createRouter entry point and inspect existing route matching and internal.navigated behavior, then compare how createRoutesView({ otherwise }) handles unmatched locations. Done means an optional pathless route opens when no routes match, closes when a match appears, avoids history writes, and rejects non-pathless routes at type and runtime.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.