nextjs - 💡(How to fix) Fix [Next.js@^14] [AppRouter] `assetPrefix` breaks api routes with same path [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#87035Fetched 2026-04-08 02:07:57
View on GitHub
Comments
1
Participants
2
Timeline
8
Reactions
0
Timeline (top)
subscribed ×2commented ×1issue_type_added ×1labeled ×1

Root Cause

Unfortunately, we can't use basePath: /my/url, because our organization requires that we can also handle optional parameters /[[lang]]/[[prov]] which we do have internal rewrites for in middleware, but this basic repro is the core of the problem blocking us from using this entirely.

Fix Action

Fix / Workaround

This issue seems resolved in future versions, but our team really needs a fix for this, or any suggested workarounds!

Code Example

Relevant Packages:
  next: ^14
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/andrew-telus/next-js-asset-prefix-bug

To Reproduce

STEPS TO REPRODUCE:

  1. npm ci
  2. npm run dev
  3. Navigate to localhost:3000 -> OK
  4. Navigate to localhost:3000/test -> OK
  5. Navigate to localhost:3000/my/url -> OK
  6. Navigate to localhost:3000/test/api/version -> OK
  7. Navigate to localhost:3000/my/url/api/version -> 404 NOT FOUND

THEN, DISABLE ASSET PREFIX

  1. next.config.mjs -> Remove assetPrefix: '/my/url',
  2. Navigate to localhost:3000/my/url/api/version -> OK

Current vs. Expected behavior

Current behaviour:

GET /my/url/api/version -> 404 when assetPrefix: '/my/url' GET /my/url/api/version -> 200 when assetPrefix: undefined

Expected behaviour:

GET /my/url/api/version -> 200 regardless of assetPrefix

Provide environment information

Relevant Packages:
  next: ^14

Which area(s) are affected? (Select all that apply)

Route Handlers

Which stage(s) are affected? (Select all that apply)

next start (local)

Additional context

This issue seems resolved in future versions, but our team really needs a fix for this, or any suggested workarounds!

Unfortunately, we can't use basePath: /my/url, because our organization requires that we can also handle optional parameters /[[lang]]/[[prov]] which we do have internal rewrites for in middleware, but this basic repro is the core of the problem blocking us from using this entirely.

extent analysis

TL;DR

The issue can be worked around by adjusting the assetPrefix configuration or using a custom middleware to handle the routing.

Guidance

  • Review the next.config.mjs file and consider removing or adjusting the assetPrefix property to resolve the routing issue.
  • Investigate using a custom middleware to handle the routing for /my/url/api/version and other similar routes.
  • Check if there are any internal rewrites in the middleware that can be adjusted to accommodate the assetPrefix configuration.
  • Consider upgrading to a future version of Next.js where this issue is reportedly resolved, if possible.

Example

No code snippet is provided as the issue is more related to configuration and routing rather than a specific code error.

Notes

The provided workaround of removing the assetPrefix property resolves the issue, but it may not be a viable solution for the team due to organizational requirements. The team's requirement for handling optional parameters /[[lang]]/[[prov]] adds complexity to the issue.

Recommendation

Apply a custom middleware workaround to handle the routing issue, as upgrading to a fixed version may not be immediately possible for the team. This approach allows the team to continue using the current version of Next.js while still resolving the routing issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING