从HTML获取dynamic路由input

我正在使用ejs作为模板语言。

<main class="content"> <% documents.forEach(function(documentObject) { %> <h1><a href="/showprofile/:username"><%= documentObject.username %></a> solved </h1> <h2><%= documentObject.problem_id %>. <%= documentObject._statement %> in <%= documentObject.time %> seconds on <%= documentObject.date_added %> . </h2> <% }) %> </main> 

我正在使用dynamic路由/showprofile/:usernameredirect/showprofile/:username 。 我需要以这样的方式创build超链接,使得documentObject.username的值作为parameter passing给:username 。 我怎样才能做到这一点 ?

您只需使用ejs函数在您的href属性中呈现用户名,而不是:username

 <h1><a href="/showprofile/<%= documentObject.username %>"><%= documentObject.username %></a> solved </h1>