question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom server Express doesn't match routes Express routes?

See original GitHub issue

https://github.com/zeit/next.js/tree/master/examples/custom-server-express

Based on the documentation for custom-server-express, my understanding is the express backend can match income requests and render the appropriate assets. The example leads me to believe it would be possible to define routes using Express However, when any of the <Link …/> components displaying on a page is clicked, the browser will bypass the matching route on the backend and proceed directly to the catch all route.

For instance, in the custom-server-express example, the following request will match ‘/a’ and respond with a rendering of the page at ‘b’.

server.get('/a', (req, res) => { return app.render(req, res, '/b', req.query) }) However, the match never seems to occur on the backend. Am I mistaken in my understanding of the documentation?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nickdandakiscommented, Aug 5, 2017

@bresson, I just cloned and ran that example. Works exactly as intended. Navigating to /a renders pages/b.js, and navigating to /b renders pages/a.js.

I now understand your question though. Using <Link> navigates to the actual page the href is set to. When you click on a <Link>, the client-side application navigates to the route, which never even reaches server.js. It’s a bit easier to understand if you click on a <Link> and then hard refresh the page, to trigger a server render (or by looking at “View source” of the page).

0reactions
timneutkenscommented, Aug 5, 2017

Okay so what you have to do is this: <Link href="/page?id=1" as="/blog/hello-world"><a>Your link</a></Link> This will render /page?id=1 but set the url to /blog/hello-world

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express route wrong match - node.js - Stack Overflow
{}); Now all works fine but as soon as I take any param out of the first route it matches the route given...
Read more >
Routing - Express.js
Express Route Tester is a handy tool for testing basic Express routes, although it does not support pattern matching. Query strings are not...
Read more >
Express Tutorial Part 4: Routes and controllers - MDN Web Docs
Main data flow diagram of an MVC express server: 'Routes' receive the HTTP. Ultimately we might have pages to show lists and detail...
Read more >
Using Express.js Routes for Promise-based Error Handling
js doesn't support promise-based route handlers by default. With many Express.js tutorials leaving out that detail, developers often get in the habit of...
Read more >
New Express 5 Features to Try - Fusebit
Express apps process client requests with specific route paths and ... For example, this would match /hello in Express 4 but would not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found