<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/zeit/next.js/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<p dir="auto">In my environment -- and it's unfortunately restricted to it, I can't reproduce it in an example -- I have the problem that all my redirects are done correctly and the server acts like expected with custom routing, but, the pages are loaded normally, not via in-place replacement (AJAX). So no XHR will be done on click on a link, instead the entire page gets reloaded.</p>
<p dir="auto">How can I debug such an issue? Are there any common pitfalls? Do you have tips to find the issue? Any help is highly appreciated.</p>
<p dir="auto">Just to show some code in case it's easy to find the issue, here's my server code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const express = require('express');
const next = require('next');
const {parse} = require('url');
const i18nextMiddleware = require('i18next-express-middleware');
const Backend = require('i18next-node-fs-backend');
const i18n = require('../hoc/i18n');

const port = parseInt(process.env.APP_PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({dev});
const handle = app.getRequestHandler();

// init i18next with server-side settings
// using i18next-express-middleware
i18n.use(Backend).use(i18nextMiddleware.LanguageDetector).init({
  preload: ['en', 'de'],
  ns: ['common', 'home', 'content'],
  backend: {
    loadPath: __dirname + '/../locales/{{lng}}/{{ns}}.json',
    addPath: __dirname + '/../locales/{{lng}}/{{ns}}-missing.json',
    jsonIndent: 2
  }
}, () =&gt; {
  app.prepare().then(() =&gt; {
    const server = express();

    // Translation routing
    server.use(i18nextMiddleware.handle(i18n));
    server.use('/locales', express.static(__dirname + '/../locales'));
    server.post('/locales/add/:lng/:ns', i18nextMiddleware.missingKeyHandler(i18n));

    // Application Routing
    server.get('*', (req, res) =&gt; {
      // Be sure to pass `true` as the second argument to `url.parse`.
      // This tells it to parse the query portion of the URL.
      const parsedUrl = parse(req.url, true);
      const {pathname, query} = parsedUrl;

      if (pathname.startsWith('/_next')) {
        return handle(req, res, parsedUrl);
      } else if (pathname === '/') {
        return app.render(req, res, '/', query);
      } else {
        return app.render(req, res, '/content', query);
      }
    });

    server.listen(port, err =&gt; {
      if (err) {
        throw err;
      }
      console.log(`&gt; Application server ready on http://localhost:${port}`);
    });
  })
});"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">express</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'express'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">next</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'next'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-kos">{</span>parse<span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'url'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">i18nextMiddleware</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'i18next-express-middleware'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-v">Backend</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'i18next-node-fs-backend'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">i18n</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'../hoc/i18n'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">const</span> <span class="pl-s1">port</span> <span class="pl-c1">=</span> <span class="pl-en">parseInt</span><span class="pl-kos">(</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">APP_PORT</span><span class="pl-kos">,</span> <span class="pl-c1">10</span><span class="pl-kos">)</span> <span class="pl-c1">||</span> <span class="pl-c1">3000</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">dev</span> <span class="pl-c1">=</span> <span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">NODE_ENV</span> <span class="pl-c1">!==</span> <span class="pl-s">'production'</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-s1">next</span><span class="pl-kos">(</span><span class="pl-kos">{</span>dev<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">handle</span> <span class="pl-c1">=</span> <span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">getRequestHandler</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-c">// init i18next with server-side settings</span>
<span class="pl-c">// using i18next-express-middleware</span>
<span class="pl-s1">i18n</span><span class="pl-kos">.</span><span class="pl-en">use</span><span class="pl-kos">(</span><span class="pl-v">Backend</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">use</span><span class="pl-kos">(</span><span class="pl-s1">i18nextMiddleware</span><span class="pl-kos">.</span><span class="pl-c1">LanguageDetector</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">init</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
  <span class="pl-c1">preload</span>: <span class="pl-kos">[</span><span class="pl-s">'en'</span><span class="pl-kos">,</span> <span class="pl-s">'de'</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
  <span class="pl-c1">ns</span>: <span class="pl-kos">[</span><span class="pl-s">'common'</span><span class="pl-kos">,</span> <span class="pl-s">'home'</span><span class="pl-kos">,</span> <span class="pl-s">'content'</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
  <span class="pl-c1">backend</span>: <span class="pl-kos">{</span>
    <span class="pl-c1">loadPath</span>: <span class="pl-s1">__dirname</span> <span class="pl-c1">+</span> <span class="pl-s">'/../locales/{{lng}}/{{ns}}.json'</span><span class="pl-kos">,</span>
    <span class="pl-c1">addPath</span>: <span class="pl-s1">__dirname</span> <span class="pl-c1">+</span> <span class="pl-s">'/../locales/{{lng}}/{{ns}}-missing.json'</span><span class="pl-kos">,</span>
    <span class="pl-c1">jsonIndent</span>: <span class="pl-c1">2</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">prepare</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-s1">server</span> <span class="pl-c1">=</span> <span class="pl-s1">express</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-c">// Translation routing</span>
    <span class="pl-s1">server</span><span class="pl-kos">.</span><span class="pl-en">use</span><span class="pl-kos">(</span><span class="pl-s1">i18nextMiddleware</span><span class="pl-kos">.</span><span class="pl-en">handle</span><span class="pl-kos">(</span><span class="pl-s1">i18n</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-s1">server</span><span class="pl-kos">.</span><span class="pl-en">use</span><span class="pl-kos">(</span><span class="pl-s">'/locales'</span><span class="pl-kos">,</span> <span class="pl-s1">express</span><span class="pl-kos">.</span><span class="pl-en">static</span><span class="pl-kos">(</span><span class="pl-s1">__dirname</span> <span class="pl-c1">+</span> <span class="pl-s">'/../locales'</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-s1">server</span><span class="pl-kos">.</span><span class="pl-en">post</span><span class="pl-kos">(</span><span class="pl-s">'/locales/add/:lng/:ns'</span><span class="pl-kos">,</span> <span class="pl-s1">i18nextMiddleware</span><span class="pl-kos">.</span><span class="pl-en">missingKeyHandler</span><span class="pl-kos">(</span><span class="pl-s1">i18n</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-c">// Application Routing</span>
    <span class="pl-s1">server</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">'*'</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">req</span><span class="pl-kos">,</span> <span class="pl-s1">res</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-c">// Be sure to pass `true` as the second argument to `url.parse`.</span>
      <span class="pl-c">// This tells it to parse the query portion of the URL.</span>
      <span class="pl-k">const</span> <span class="pl-s1">parsedUrl</span> <span class="pl-c1">=</span> <span class="pl-en">parse</span><span class="pl-kos">(</span><span class="pl-s1">req</span><span class="pl-kos">.</span><span class="pl-c1">url</span><span class="pl-kos">,</span> <span class="pl-c1">true</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
      <span class="pl-k">const</span> <span class="pl-kos">{</span>pathname<span class="pl-kos">,</span> query<span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-s1">parsedUrl</span><span class="pl-kos">;</span>

      <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">pathname</span><span class="pl-kos">.</span><span class="pl-en">startsWith</span><span class="pl-kos">(</span><span class="pl-s">'/_next'</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-s1">handle</span><span class="pl-kos">(</span><span class="pl-s1">req</span><span class="pl-kos">,</span> <span class="pl-s1">res</span><span class="pl-kos">,</span> <span class="pl-s1">parsedUrl</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
      <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">pathname</span> <span class="pl-c1">===</span> <span class="pl-s">'/'</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">render</span><span class="pl-kos">(</span><span class="pl-s1">req</span><span class="pl-kos">,</span> <span class="pl-s1">res</span><span class="pl-kos">,</span> <span class="pl-s">'/'</span><span class="pl-kos">,</span> <span class="pl-s1">query</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
      <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">render</span><span class="pl-kos">(</span><span class="pl-s1">req</span><span class="pl-kos">,</span> <span class="pl-s1">res</span><span class="pl-kos">,</span> <span class="pl-s">'/content'</span><span class="pl-kos">,</span> <span class="pl-s1">query</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
      <span class="pl-kos">}</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-s1">server</span><span class="pl-kos">.</span><span class="pl-en">listen</span><span class="pl-kos">(</span><span class="pl-s1">port</span><span class="pl-kos">,</span> <span class="pl-s1">err</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">err</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">throw</span> <span class="pl-s1">err</span><span class="pl-kos">;</span>
      <span class="pl-kos">}</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">`&gt; Application server ready on http://localhost:<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">port</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<h2 dir="auto">Context</h2>


<p dir="auto">Navigating pages via AJAX.</p>
<h2 dir="auto">Your Environment</h2>

<table role="table">
<thead>
<tr>
<th>Tech</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<tr>
<td>next</td>
<td>5.0.0</td>
</tr>
<tr>
<td>node</td>
<td>6.11.3</td>
</tr>
<tr>
<td>OS</td>
<td>Win 10</td>
</tr>
<tr>
<td>browser</td>
<td>Chrome &amp; FF latest</td>
</tr>
<tr>
<td>etc</td>
<td></td>
</tr>
</tbody>
</table>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/zeit/next.js/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h2 dir="auto">Expected Behavior</h2>
<p dir="auto">I love the new static HTML export functionality in next 3.x, but it is behaving somewhat differently than I would expect. If you have a next.config.js that looks like this:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// next.config.js
module.exports = {
  exportPathMap: function() {
    return {
      &quot;/&quot;: {page: &quot;/&quot;},
      &quot;/page2&quot;: {page: &quot;/page2&quot;},
    };
  },
};"><pre class="notranslate"><span class="pl-c">// next.config.js</span>
<span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-c1">exports</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  <span class="pl-en">exportPathMap</span>: <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-kos">{</span>
      <span class="pl-s">"/"</span>: <span class="pl-kos">{</span><span class="pl-c1">page</span>: <span class="pl-s">"/"</span><span class="pl-kos">}</span><span class="pl-kos">,</span>
      <span class="pl-s">"/page2"</span>: <span class="pl-kos">{</span><span class="pl-c1">page</span>: <span class="pl-s">"/page2"</span><span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-kos">}</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">then I would expect <code class="notranslate">next export</code> to create an <code class="notranslate">out</code> directory like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="index.html
page2.html"><pre class="notranslate"><code class="notranslate">index.html
page2.html
</code></pre></div>
<p dir="auto">and I would expect <code class="notranslate">Link</code> components that link to <code class="notranslate">/page2</code> to result in URLs that link to <code class="notranslate">/page2</code>.</p>


<h2 dir="auto">Current Behavior</h2>
<p dir="auto">Instead, the config above produces an <code class="notranslate">out</code> directory like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="index.html
page2/index.html"><pre class="notranslate"><code class="notranslate">index.html
page2/index.html
</code></pre></div>
<p dir="auto">and <code class="notranslate">Link</code> components that link to <code class="notranslate">/page2</code> result in URLs that link to <code class="notranslate">/page2/</code>.</p>


<h2 dir="auto">Context</h2>
<p dir="auto">I'm trying to make a next site that can be easily hosted on a static server, but this feature means that all of the URLs in the site have an unnecessary trailing slash. This is not only a bit unsightly, but it's also not the same behavior as <code class="notranslate">next start</code>.</p>


<h2 dir="auto">Your Environment</h2>

<table role="table">
<thead>
<tr>
<th>Tech</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<tr>
<td>next</td>
<td>3.0.6</td>
</tr>
<tr>
<td>node</td>
<td>8.2.1</td>
</tr>
<tr>
<td>OS</td>
<td>macOS Sierra</td>
</tr>
<tr>
<td>browser</td>
<td>N/A</td>
</tr>
<tr>
<td>etc</td>
<td></td>
</tr>
</tbody>
</table>