To modify the index.js routing rule:
varExpress = require (' Express ');varRouter =Express. Router ();/*GET home page.*/Router.get (‘/‘,function(req, res, next) {Res.render (' Index ', {title: ' home Page ' });}); Router.get ('/reg ',function(Req,res,next) {Res.render (' Reg ', {title: ' Register ' });}); Router.post ('/reg ',function(Req,res,next) {}); Router.get ('/login ',function(Req,res,next) {Res.render (' Login ', {title: ' Login ' });}); Router.post ('/reg ',function(Req,res,next) {}); Router.get ('/post ',function(Req,res,next) {Res.render (' Post ', {title: ' Publish ' });}); Router.post ('/post ',function(Req,res,next) {}); Router.get ('/logout ',function(Req,res,next) {}); Module.exports= Router;
2. Modify the Index.ejs view
<%-include header%> This is the home page <%-include footer%>
3. New Header.ejs
<! DOCTYPE html>
4. New Footer.ejs
</article> </body>
5, added Login.ejs Reg.ejs post.ejs
<%-include header%> <form method= "POST" > User name:<input type= "text" name= "name"/> <br/> Password:<input type= "password" name= "password"/><br/> <input type= "Submit" value= "Login"/> </form><%-include footer%>
<%-include header%> <form method= "POST" > User name:<input type= "text" name= "name"/> <br/> Password:<input type= "password" name= "password"/><br/> Confirm Password: <input type= "Password" name= "Repassword"/><br/> Email:<input type= "email" name= "email" /><br/> <input type= "Submit" value= "register"/> </form><%- include footer%>
<%-include header%> <form method= "POST" > title:<br/> <input type= "text" Name= "title"/><br/> Body:<br/> <textarea name= "POST" rows= "cols=" > </textarea><br/> <input type= "Submit" value= "Login"/> </form><%-include footer% >
Now the browser can access the form page:
Use Express+mongodb to build multiplayer blog learning (2) Routing and templates