Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

388
Vistas
How to add a filename extension to an Next.js url?

Example : I need to redirect this URL : https://example.com/data/publications to this one : https://example.com/data/publications.json

I already tried Next.js redirection but I failed to add a string that is not starting with /

Example, this doesn't work :

  async redirects() {
    return [
      {
        source: '/data/:slug',
        destination: '/data/:slug.json',
        permanent: true,
      },
    ]
  },

Adding () around .json doesn't help

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

How about using a middleware? Middleware is a function that executes when client connects to a specific route.

To use middleware; inside your "pages/data" folder, create "_middleware.js" file and use the code below. This code checks if the url has "json" extension end of it. If it doesn't, then it redirects the client to the url with "json" version.

import { NextResponse } from 'next/server';

export default function myMiddleware(req, e) {
  if (!req.url.endsWith("json")) return new NextResponse.redirect(`${req.url}.json`);
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda