next-runtime icon indicating copy to clipboard operation
next-runtime copied to clipboard

Fix trailing slashes with an edge function

Open MarcL opened this issue 2 years ago • 9 comments

By default Next.js will redirect urls with trailing slashes to their counterpart without a trailing slash. For example /about/ will redirect to /about. This has caused issues (see below).

@ascorbic created a proof of concept to add or remove trailing slashes in an edge function. This can be used to enable or disabled trailing slashes based upon the Next.js configuration.

Documentation

https://github.com/ascorbic/slash-edge https://nextjs.org/docs/api-reference/next.config.js/trailing-slash

Related Issues

#1329 #998 #1144 #1788

MarcL avatar Jul 05 '22 14:07 MarcL

From @ascorbic

This can probably wait until the Edge router is done.

nickytonline avatar Jul 11 '22 14:07 nickytonline

Highly needed due to SEO requirements. Please don't forget

mike-essen avatar Nov 11 '22 13:11 mike-essen

We won't @mike-essen. It'll roll out with our work on edge routing. 👍

MarcL avatar Nov 16 '22 15:11 MarcL

Is there any ETA on the work on edge routing? 👍

PFJoey avatar Nov 19 '22 12:11 PFJoey

Not yet @PFJoey. We'll keep you updated as we know more.

MarcL avatar Nov 21 '22 08:11 MarcL

What is the status on this one?

hk86 avatar Feb 06 '23 11:02 hk86

@hk86 we are currently working on a new edge router that will allow us to handle more complex routing cases and will include better trailing slash handling. in the meantime you can use the following edge function to add or strip trailing slashes on static pages https://github.com/ascorbic/slash-edge

orinokai avatar Feb 24 '23 17:02 orinokai

Any idea about when this is going to be resolved?

jessicaribeiroalves avatar Jun 07 '23 13:06 jessicaribeiroalves

I have fixed some issues with ascorbic's functions that handles querystrings and _redirects

Netlify Edge Functions

devotox avatar Nov 03 '23 11:11 devotox

The team at Netlify have now released the new v5 Next.js runtime which has support for both pages and app router, on-demand and time-based revalidation, automatic fine-grained cache control, and automatic image optimization using Netlify's image CDN. This issue should be fixed in the new runtime.

You can find the documentation and additional information here: Next.js on Netlify

The v4 runtime is now in the maintenance support phase with no new features being added. Occasional bug fixes and security patches will be applied when needed.

Thanks!

MarcL avatar Apr 23 '24 12:04 MarcL