Next.js Discord

Discord Forum

redirects to "/index.txt" bug

Unanswered
Bonga shad posted this in #help-forum
Open in Discord
Bonga shadOP
Hello, Anyone knows how to solve to this bug?

const submitTraitResultMutation = useMutation({
        mutationFn: async () => submitTraitResult(),
        onSuccess: () => {
            router.push('/trait/result')
        },
        onError: (error) => {
            ....
        },
    })

actual: it redirect to '/trait/result/index.txt'
expected: redirect to '/trait/result'

- not using canary
Version: 15.5.18

next.config.mjs
import analyzer from '@next/bundle-analyzer'
import path from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const withBundleAnalyzer = analyzer({
    enabled: process.env.ANALYZE === 'true',
})
const getDistDir = () => {
    if (process.env.NEXT_PUBLIC_ENV === 'LOCAL') {
        return undefined
    }
    return process.env.NEXT_PUBLIC_ENV === 'PRD' ? 'prd' : 'nonprd'
}
/** @type {import('next').NextConfig} */
const nextConfig = {
    output: 'export',
    distDir: getDistDir(),
    reactStrictMode: true,
    trailingSlash: true,
    images: {
        minimumCacheTTL: 0,
        unoptimized: true,
        domains: [
            'xxxx',
            'xxxx',
        ],
    },
    sassOptions: {
        includePaths: [path.join(__dirname, 'src', 'styles')],
    },
    webpack: (config) => {
        config.externals.push('pino-pretty', 'lokijs', 'encoding')
        config.watchOptions = {
            ...config?.watchOptions,
            ignored: ['node_modules', '.next', 'nonprd', 'prd'],
        }
        return config
    },
    compiler: {
        removeConsole: process.env.NODE_ENV === 'production',
    },
    turbopack: {
        resolveExtensions: ['.mdx', '.tsx', '.ts', '.jsx', '.js', '.mjs', '.json'],
        resolveAlias: {},
        rules: {
            '*.svg': {
                loaders: ['@svgr/webpack'],
                as: '*.js',
            },
        },
    },
}
export default withBundleAnalyzer(nextConfig)

1 Reply

@Bonga shad Hello, Anyone knows how to solve to this bug? const submitTraitResultMutation = useMutation({ mutationFn: async () => submitTraitResult(), onSuccess: () => { router.push('/trait/result') }, onError: (error) => { .... }, }) actual: it redirect to '/trait/result/index.txt' expected: redirect to '/trait/result' - not using canary Version: 15.5.18 next.config.mjs import analyzer from '@next/bundle-analyzer' import path from 'path' import { fileURLToPath } from 'url' const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) const withBundleAnalyzer = analyzer({ enabled: process.env.ANALYZE === 'true', }) const getDistDir = () => { if (process.env.NEXT_PUBLIC_ENV === 'LOCAL') { return undefined } return process.env.NEXT_PUBLIC_ENV === 'PRD' ? 'prd' : 'nonprd' } /** @type {import('next').NextConfig} */ const nextConfig = { output: 'export', distDir: getDistDir(), reactStrictMode: true, trailingSlash: true, images: { minimumCacheTTL: 0, unoptimized: true, domains: [ 'xxxx', 'xxxx', ], }, sassOptions: { includePaths: [path.join(__dirname, 'src', 'styles')], }, webpack: (config) => { config.externals.push('pino-pretty', 'lokijs', 'encoding') config.watchOptions = { ...config?.watchOptions, ignored: ['node_modules', '.next', 'nonprd', 'prd'], } return config }, compiler: { removeConsole: process.env.NODE_ENV === 'production', }, turbopack: { resolveExtensions: ['.mdx', '.tsx', '.ts', '.jsx', '.js', '.mjs', '.json'], resolveAlias: {}, rules: { '*.svg': { loaders: ['@svgr/webpack'], as: '*.js', }, }, }, } export default withBundleAnalyzer(nextConfig)
Slovenský Cuvac
hi there,

Because you are using:

output: "export"
trailingSlash: true

the /trait/result/index.txt request may be expected rather than an actual
redirect.

In App Router static exports, Next generates index.html for the page and a
separate index.txt React Server Component payload for client-side navigation.

Could you confirm whether /trait/result/index.txt appears in the browser
address bar, or only in DevTools → Network?

If the address bar remains /trait/result/, the navigation is working and
index.txt is only the internal route payload.

If the address bar itself changes to index.txt, then I would check:

1. Whether this mutation is triggered from a form that is also submitting
natively
2. The hosting/CDN rewrite configuration
3. Whether /trait/result/index.html and index.txt both exist in the export
4. The response Content-Type and initiator for the index.txt request

You can also try the canonical exported route explicitly:

router.push("/trait/result/")

Which of the platforms serves the exported files: S3/CloudFront, Nginx, Cloudflare,
Vercel, or something else?