Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

383
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda