Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: koajs/router
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v15.3.2
Choose a base ref
...
head repository: koajs/router
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v15.4.0
Choose a head ref
  • 2 commits
  • 13 files changed
  • 1 contributor

Commits on Mar 16, 2026

  1. feat: add router event system and ctx.routeMatched for not-found hand…

    …ling
    
    Add an experimental `router.on()` event API and a `ctx.routeMatched` flag
    to give users first-class, zero-boilerplate tools for handling unmatched
    requests.
    
    New: router.on() event system (experimental)
    - Add `RouterEvents` named-constant object (`RouterEvents.NotFound`)
    - Add `RouterEventEmitter` that composes handlers via koa-compose
    - Add `resolveEvent()` to accept a string, constant, or selector function
      `(events) => events.NotFound`
    - Add `router.on(event, handler)` method on `Router` — returns `this` for
      chaining; multiple handlers for the same event are composed in order
    - Wire `not-found` event into `Router#routes()`: fires instead of `next()`
      when no route matched path + method
    - Leave TODO comments for planned but not-yet-active events:
      `dispatch`, `match`, `method-not-allowed`
    
    New: ctx.routeMatched
    - Add `routeMatched?: boolean` to `RouterContext` type
    - Router sets it to `true` when a route matched and `false` otherwise,
      before any handlers run — enables simple app-level 404 detection
    
    Exports
    - Re-export `RouterEvents`, `RouterEvent`, `RouterEventSelector` from
      the package root (`src/index.ts`) and `src/types.ts`
    
    Tests
    - Add `test/utils/router-events.test.ts` covering the emitter, resolver,
      and `RouterEvents` constants
    - Expand `test/router.test.ts` with `router.on()` and `ctx.routeMatched`
      integration tests
    
    Recipes & docs
    - Add `recipes/not-found-handling/not-found-handling.ts` with 8 complete
      approaches (ctx.routeMatched, ctx.matched array, catch-all route,
      router.on() with all three call forms, composed handlers, full example)
    - Add `recipes/not-found-handling/not-found-handling.test.ts` covering
      all 8 approaches end-to-end via supertest
    - Update `recipes/README.md` to list the new recipe
    - Add section 6.3 "New features in v15" to `FULL_MIGRATION_TO_V15+.md`
      documenting both additions with examples and a new-exports table
    - Update `README.md` with usage examples for `router.on()` and
      `ctx.routeMatched`
    3imed-jaberi committed Mar 16, 2026
    Configuration menu
    Copy the full SHA
    54821e3 View commit details
    Browse the repository at this point in the history
  2. v15.4.0

    3imed-jaberi committed Mar 16, 2026
    Configuration menu
    Copy the full SHA
    aa24f20 View commit details
    Browse the repository at this point in the history
Loading