Node.js,哈巴狗。如何设置到另一个哈巴狗文件的链接

问题描述 投票:0回答:1

我绝对不是pug和javascript的新手。我有一个小问题,谁能告诉我怎么了?我的目标是用文本制作多个.pug文件,以便不能按链接并转到另一个文本.pug文件。我使用node.js创建了一个快速应用程序。我有一个简单的index.pug。

extends layout

block content

  h1= title
  p Welcome to #{title} 
  a(href="about.pug") this is the link text


因此,我只想从我的主文件index.pug链接到about.pug文件,该文件位于同一文件夹中,并且内部具有完全相同的代码。但是,每次我单击链接时,它只会说未找到404(如果我使用网站链接(例如www.youtube.com),则链接会完成任务)。我不太明白...文件存在,但是它说找不到404 ...我需要对路线做一些操作吗?我在那里没有做任何更改。

javascript node.js pug
1个回答
0
投票

因此,请将href更改为'/about'

(href="/about") this is the link text

并在Express服务器中为其创建路由:

router.get('/about', (req, res) => {
    res.render('about', {title: "something"});
});
© www.soinside.com 2019 - 2024. All rights reserved.