How to use Node.js to jump to pages? This article will introduce to you how to implement html page jump based on Node. I hope it will be helpful to you!
Recently, I am using Node.js and html to learn the relevant knowledge of the page. When I learn the page jump, , there was a problem of unsuccessful jump, recorded here for future reference.
In Node.js, the express framework is mainly used, and html is used on the front end.
This small Demo mainly involves four files, including:
The code part is as follows:
const express = require('express') const app = express() const router = require('./router') app.engine('html',require('express-art-template')) app.use(router) app.listen(3000,() => { console.log('successful...') })
The code part is as follows:
const express = require('express') //创建路由实例 const router = express.Router() router.get('/',(req,res) => { res.render('main.html') }) module.exports = router //暴露接口
code part is as follows:
<div> <a href="/new" >页面跳转</a> <!--跳转至新页--> </div>
The part of the code is as follows:
<div> <th>成功实现跳转</th> </div>
command in the small black screen:
node main.js
http://localhost:3000:
You can see a hyperlink to jump to the page. Click this hyperlink:
page No effective jump is achieved.
code to router.js:
router.get('/new',function(req,res){ res.render('new.html') })
localhost:3000/new, use res .render jump.
The problem is now solved!
nodejs tutorial! !
The above is the detailed content of How to use Node.js to jump to html pages. For more information, please follow other related articles on the PHP Chinese website!