<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?q=is%3Aissue">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'm using a custom Express server around my Next.js application and I would like to be able to deal with unhandled routes myself.</p>
<h2 dir="auto">Current Behavior</h2>


<p dir="auto">Currently Next.js handles all routes and <a href="https://github.com/zeit/next.js/blob/eff27bdcfb7208e9cdadbfbeada4467384ffd379/server/index.js#L337">renders a 404 page</a> when a matching route isn't found. I haven't found a way to circumvent this behavior other than by avoiding the <code class="notranslate">nextApp.render()</code> altogether, but that requires me to deal with <code class="notranslate">/_next/</code> routes and hot reloading myself. I consider <code class="notranslate">defineRoutes()</code> to not be part of Next's public API so I don't want to use it.</p>
<h2 dir="auto">Context</h2>


<p dir="auto">I'm implementing a new frontend for a legacy application. I want to migrate away from the old application page-by-page. I do this by having Express proxy any unhandled requests (as the final catch-all route) to the legacy environment. At the moment this is impossible due to Next.js handling 404s, so I have to resort to using a whitelist of "already implemented routes".</p>
<h2 dir="auto">Proposal</h2>
<p dir="auto">I propose adding a <code class="notranslate">finalizeRequests</code> (default <code class="notranslate">true</code>) option to <code class="notranslate">next({...options})</code> which allows us to disable the handling of unknown routes. Specifically this concerns <a href="https://github.com/zeit/next.js/blob/eff27bdcfb7208e9cdadbfbeada4467384ffd379/server/index.js#L336-L341">these lines of code</a>.</p>
<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">If a component defined at <code class="notranslate">pages/_error.js</code> returns props from its <code class="notranslate">getInitialProps</code> on the server side, those props should be passed in when rendering the error component.</p>
<h2 dir="auto">Current Behavior</h2>
<p dir="auto">The server-generated props get thrown out when <code class="notranslate">client/index.js</code>’s <code class="notranslate">render</code> method checks for an <code class="notranslate">err</code> and calls <code class="notranslate">renderError</code> passing just <code class="notranslate">props.err</code> and not <code class="notranslate">props.props</code>.</p>
<h2 dir="auto">Steps to Reproduce (for bugs)</h2>


<ol start="0" dir="auto">
<li>Use <code class="notranslate">NODE_ENV=production</code> to avoid the dev-only error behavior</li>
<li>Make an <code class="notranslate">_error</code> component that returns values from <code class="notranslate">getInitialProps</code> that depend upon values known on the server.</li>
<li>Throw an exception from another page’s <code class="notranslate">getInitialProps</code> method</li>
<li>When you visit that page, your <code class="notranslate">_error</code> component will be rendered, but its props will be from the client-side <code class="notranslate">getInitialProps</code> call from the client’s <code class="notranslate">renderError</code> function.</li>
</ol>
<h2 dir="auto">Contributing</h2>
<p dir="auto">I’m happy to open a PR; I think that the fix would be to pass an optional set of props to <code class="notranslate">renderError</code> when <code class="notranslate">render</code> calls it in <code class="notranslate">client/index.js</code>. Only if those props are not provided would <code class="notranslate">renderError</code> call <code class="notranslate">loadGetInitialProps</code>.</p>
<p dir="auto">If that’s a proper solution I can code it up.</p>
<h2 dir="auto">Context</h2>
<p dir="auto">I initialize a bit of my app’s state (API keys and the like) by passing values on the <code class="notranslate">req</code> object that’s given on the server to <code class="notranslate">getInitialProps</code>. If the first page a visitor sees is an error page, then these values from the server are thrown away, leaving my app partially un-initialized.</p>
<h2 dir="auto">Your Environment</h2>
<p dir="auto">Using Next 4.1.3 in my app, but looking through the code indicates that this is broken on HEAD as well.</p>