redirect operator
- Dominant language
- TypeScript
- Stars
- 8
- Forks
- 2
- Avg merge
- 13h 44m
- Merged PRs (30d)
- 1
Description
### Problem
atomic-router ships a `redirect` helper — a declarative "when clock fires, open this route" one-liner. In `@effector/router` the same intent requires a manual `sample({ clock, source, fn, target: route.open })` for every redirect, which is verbose and a friction point when migrating from atomic-router.
### Proposed solution
Add a top-level `redirect` operator (plugin-friendly factory, same tier as `chainRoute`/`group`):
```ts
import { redirect } from '@effector/router';
// declarative form — returns void
redirect({
clock: userSaved, // Unit | Unit[]
route: routes.profile,
params: (user) => ({ id: user.id }), // value | Store | (clock) => value
query: { welcome: 'true' },
replace: true,
});
// clock-less form — returns EventCallable trigger
const goHome = redirect({ route: routes.home });
```
Each of `params`/`query`/`replace` accepts a static value, a `Store`, or a function of the clock payload. Implementation: normalize all three into stores/`fn` and wire a single `sample` into `route.open`. Overloads: with `clock` → `void`; without `clock` → `EventCallable` (atomic-router parity, used as an imperative trigger or `sample` target).
### Alternatives considered
Manual `sample` into `route.open` — works today but loses the declarative shape and makes atomic-router migration noisy.
### Package
`@effector/router` (core)
Contributor guide
Research direction
Start in the @effector/router core beside the existing chainRoute and group operators, and inspect how sample wires into route.open. Compare the clock and clock-less forms, including normalization of params, query, and replace. Done means both forms have the stated overloads and support the proposed static, Store, and clock-payload values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100