课程: Learning Full-Stack JavaScript Development: MongoDB, Node, and React

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Server-side rendering of a custom path

Server-side rendering of a custom path

- [Instructor] Now that we have a URL for a contest, let's see what happens when we refresh this page. We did not define a handler for this page on the server, so we need to define that handler and include this component in the server-side logic as well. Let's do that. The first thing that we need to modify is server.ts. In server.ts we said handle the root path. We also needed to handle this path, /contest/id. My plan is to make the server render function path aware as well, so we could reuse this logic for both the root path and the single contest page path. And Express actually support passing an array here with multiple paths to share the same request handling logic. So in here, we can do /contest/ a dynamic contest ID, which is a request param. So just with that change, if we test now and refresh the same page, it'll be handled server-side but it looks like we have a problem in main.js. So let me figure out that problem…

内容