#How to handle trailing slash behaviour with next.js

4 messages · Page 1 of 1 (latest)

long bluff
#

Does anyone consume a django api with next js?
Next automatically redirects requests with a trailing backslash to one without.
https://nextjs.org/docs/api-reference/next.config.js/trailing-slash
Django automatically adds a slash to urls without one
https://docs.djangoproject.com/en/3.2/ref/settings/#append-slash

Causing infinite loops. Do you all handle the missmatch in next or in django?

Configure Next.js pages to resolve with or without a trailing slash.

late pilot
#

I'd switch Next. This is because you may add other URLs to your django app that are used by browsers/users directly. Avoiding odd cases in that scenario is more important than keeping next's default config.

karmic raven
#

APPEND_SLASH can be turned off with a setting. Making the slash optional in your URL patterns might also be a valid workaround.

#

Changing the redirect status code from 301 / 302 to 308 might also help in some situations (not sure if Django uses 308 by default these days).