react-navigation/react-navigation · error

A 'path' needs to be specified when specifying 'exact: true'

Error message

A 'path' needs to be specified when specifying 'exact: true'. If you don't want this screen in the URL, specify it as empty string, e.g. `path: ''`.

What it means

In the linking config, `exact: true` means this screen's pattern must match the URL exactly with no prefix inheritance, which only makes sense when the screen declares its own `path`. If exact is set but path is undefined, the library throws at config creation time so the mistake is caught before any linking happens.

Source

Thrown at packages/core/src/getPathFromState.tsx:475

const createConfigItem = (
  config: PathConfig<{}> | string,
  parentParts?: PatternPart[]
): ConfigItem => {
  if (typeof config === 'string') {
    const ownParts = getPatternParts(config);

    if (parentParts) {
      return {
        parts: combinePatternParts(parentParts, ownParts),
        ownParts,
      };
    }

    return { parts: ownParts, ownParts };
  }

  if (config.exact && config.path === undefined) {
    throw new Error(
      "A 'path' needs to be specified when specifying 'exact: true'. If you don't want this screen in the URL, specify it as empty string, e.g. `path: ''`."
    );
  }

  // If an object is specified as the value (e.g. Foo: { ... }),
  // It can have `path` property and `screens` prop which has nested configs
  const ownParts = config.path ? getPatternParts(config.path) : [];
  const parts =
    config.exact !== true
      ? combinePatternParts(parentParts || [], ownParts)
      : ownParts.length
        ? ownParts
        : undefined;

  const screens =
    'screens' in config && config.screens
      ? createNormalizedConfigs(config.screens, parts)
      : undefined;

View on GitHub (pinned to ab1319d6bb)

Solutions

  1. Add an explicit path: Profile: { path: 'u/:id', exact: true }.
  2. If the screen should live at the root URL, set path: '' explicitly alongside exact: true.
  3. Remove exact: true if you actually want the screen to extend the parent's path prefix.
  4. Verify the config object keys (path not paths) and that path isn't undefined at runtime.

Example fix

// before
const config = { screens: { Profile: { exact: true } } };
// after
const config = { screens: { Profile: { path: 'u/:id', exact: true } } };
// or, for root:
const config = { screens: { Profile: { path: '', exact: true } } };
Defensive patterns

Strategy: validation

Validate before calling

function validateLinkingConfig(screens) {
  for (const [name, cfg] of Object.entries(screens)) {
    if (cfg && typeof cfg === 'object' && cfg.exact && cfg.path === undefined) {
      throw new Error(`Screen '${name}' has exact: true but no path (use path: '' for root)`);
    }
    if (cfg?.screens) validateLinkingConfig(cfg.screens);
  }
}
validateLinkingConfig(linking.config.screens);

Type guard

function isValidScreenConfig(c) {
  return !(c != null && typeof c === 'object' && c.exact === true && c.path === undefined);
}

Try / catch

try {
  const normalized = createNormalizedConfigs(screens);
} catch (err) {
  if (err.message.includes("exact: true")) {
    console.error('Linking config error:', err.message);
  } else throw err;
}

Prevention

When it happens

Trigger: Declaring a screen config like Profile: { screen: Profile, exact: true } (or { exact: true, screens: {...} }) in the `screens` linking config without a `path` key.

Common situations: Copying a config entry that had a path and removing the path but keeping exact; typos like `paths:` instead of `path:`; intending '' (empty path) but leaving the key out.

Related errors


AI-assisted analysis of react-navigation/react-navigation@ab1319d6bb (2026-08-31). Data as JSON: /api/errors/6d36a2e4f13eb57e. Report an issue: GitHub.