前端学习(1315):路由
生活随笔
收集整理的這篇文章主要介紹了
前端学习(1315):路由
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//引入系統模塊http//創建網站服務器//為網站添加請求事件
const http = require('http');
const url = require('url');
const app = http.createServer();app.on('request', (req, res) => {//獲取請求方式const method = req.method.toLowerCase();//獲取請求地址const pathname = url.parse(req.url).pathname;res.writeHead(200, {'content-type': 'text/html;charset=utf8'});if (method == 'get') {if (pathname == '/' || pathname == 'index') {res.end('歡迎來到首頁')} else if (pathname == '/list') {res.end('歡迎來到列表頁')} else {res.end('你訪問的頁面不存在')}} else if (method == 'post') {}});
app.listen(3000);
console.log('服務器啟動成功');
運行結果
總結
以上是生活随笔為你收集整理的前端学习(1315):路由的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何下载微信支付证书(API证书)
- 下一篇: 2017年html5行业报告,云适配发布