簡體   English   中英

為什么 html 路由在 express.js 中不起作用?

[英]Why is html route not working in express.js?

所以這是一個非常微不足道的問題......我的客戶端代碼中有一個 get 請求。

function tosurvey(){$.get( "/survey", d=>d?console.log("Redirected"):false);}

和后面的聽眾

 router.get('/survey', function(req, res) {
        res.sendFile('survey.html', { root: path.join(__dirname, '../public') });
    });

但是,它不起作用。 如果您直接轉到 /survey,它確實有效,但是 get 請求也指向 /survey,並且應該在 onclick 上發生,因為它綁定到前面的 click 事件。

這修復了它。

    let x = window.location.pathname;
    x=x.split("/");
    x.pop();
    x=x.join('/');
   $.get("/", d=>d?(console.log("Redirected"),window.location=x+'/'):false);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM