emberjs/ember.js · error · Error

More context objects were passed than there are dynamic segm

Error message

More context objects were passed than there are dynamic segments for the route: ${targetRouteName}

What it means

router_js throws this from NamedTransitionIntent.applyToHandlers when a transition like transitionTo('post', post, comment, extra) supplies more context objects than the target route chain has dynamic segments. Extra contexts cannot be attached to any route, so the intent is rejected rather than silently dropping them.

Source

Thrown at packages/router_js/lib/transition-intent/named-transition-intent.ts:142

      if (i >= invalidateIndex || newHandlerInfo.shouldSupersede(oldHandlerInfo)) {
        invalidateIndex = Math.min(i, invalidateIndex);
        handlerToUse = newHandlerInfo;
      }

      if (isIntermediate && !checkingIfActive) {
        handlerToUse = handlerToUse.becomeResolved(
          null,
          // SAFETY: This seems to imply that it would be resolved, but it's unclear if that's actually the case.
          handlerToUse.context as ModelFor<R>
        );
      }

      newState.routeInfos.unshift(handlerToUse);
    }

    if (objects.length > 0) {
      throw new Error(
        'More context objects were passed than there are dynamic segments for the route: ' +
          targetRouteName
      );
    }

    if (!isIntermediate) {
      this.invalidateChildren(newState.routeInfos, invalidateIndex);
    }

    merge(newState.queryParams, this.queryParams || {});
    if (isIntermediate && oldState.queryParams) {
      merge(newState.queryParams, oldState.queryParams);
    }

    return newState;
  }

  invalidateChildren(handlerInfos: InternalRouteInfo<R>[], invalidateIndex: number) {

View on GitHub (pinned to 26f97246a8)

Solutions

  1. Count the dynamic segments on the target route chain and pass exactly that many context objects.
  2. If an extra argument is metadata, pass it as a second argument after a queryParams object or via route options, not as a context.
  3. Update stale transitionTo/link-to call sites after removing nested resources.
  4. For optional data, use a service or queryParams instead of an extra positional context.

Example fix

// before
this.transitionTo('post.comments', post, comment, sortBy);
// after
this.transitionTo('post.comments', post, comment, { queryParams: { sort: sortBy } });
Defensive patterns

Strategy: validation

Validate before calling

const dynamicSegments = countDynamicSegments(routeName); // parse router map e.g. /posts/:post_id/comments/:comment_id
if (contexts.length > dynamicSegments) throw new Error(`Pass only ${dynamicSegments} contexts to ${routeName}`);

Type guard

null

Try / catch

try { router.transitionTo('post.comments', post, comment); }
catch (e) { if (e.message.startsWith('More context objects')) { console.error('extra context passed:', e); } else throw e; }

Prevention

When it happens

Trigger: route.transitionTo('routeName', ctx1, ctx2, ...) or {{link-to}} with more positional models/objects than the sum of dynamic segments (:id etc.) across the matched routes.

Common situations: Passing (model, queryParam-ish extra arg) by mistake to transitionTo; refactoring a route to drop a nested dynamic segment while callers still pass two contexts; accidentally passing a second argument like options object positionally.

Related errors


AI-assisted analysis of emberjs/ember.js@26f97246a8 (2026-09-01). Data as JSON: /api/errors/236bb66792de71f2. Report an issue: GitHub.