Routing with parameters in jade from one page to another

淺唱寂寞╮ 提交于 2019-12-11 15:25:54

问题


As i am new to nodejs and express, i would need some help here which could solve my problem. I have table(jade) on the page track.jade which contains information, with "ID" linking to another page. Successfully i can route to another page. But i need to pass the parameters from the table "track.jade" to another page within the table.

How can i achieve this? as i am not able find any article which could determine this issue.

    mixin session(AWB_NO, Product_Name, PCS, Weight, Gross_Weight, DOP, DOE)
tr
td.session(data-sort-value="#{session_name}")
.flex.sm
div
a.name(href="/track/dist.jade") #{AWB_NO}
div
td.min(data-label="Name") #{Product_Name}
td.min(data-label="file") #{PCS}
td.min(data-label="s_name") #{Weight}
td.min(data-label="r_name") #{Gross_Weight}
td.min(data-label="Date") #{DOP}
td.min(data-label="Date") #{DOE}
td.remove
a.btn-remove
img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/5102/remove.svg", alt="Remove Session")
span Remove 
.container
.event-registration.reset
.content.wide
.row-inset
table.table-default.table-striped.table-bordered.sortable
thead(data-header="true")
tr
th(data-sort-column="true") AWB NO
th(data-sort-column="true") Product Name
th(data-sort-column="true") PCS
th(data-sort-column="true") Weight
th(data-sort-column="true") Gross Weight
th(data-sort-column="true") Date of Packing
th(data-sort-column="true") Date of Expiry
// th(data-sort-column="true") DOR
th
tbody(data-body="true")
+session("16783","Tuna Super","10","12,6","13","03/28/2017","04/28/2017")
+session("17670936423","Fresh Sword Fish","1","12,8","13,6","03/28/2017","04/28/2017")
+session("178529","Fresh Fish","8","10","11","03/28/2017","04/28/2017")
+session("16254","Baramundi","5","11","12","03/28/2017","04/28/2017")

i had tried routing from one page to another page with the url localhost:3000/track/dist.jade


回答1:


You need to change the href value to the route set in the express router. The parameter can then be received in the dist route as a request param.

track.jade

a.name(href="/dist/" + AWB_NO ) #{AWB_NO}

dist.js

router.get('/dist/:awb', ensureLoggedIn, utils.checkAdmin, function (req, res, next) {
    res.render('dist',{
        AWB_NO: req.params.awb
    })    
});


来源:https://stackoverflow.com/questions/56593575/routing-with-parameters-in-jade-from-one-page-to-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!