如何在 SPFx 中将 link 渲染为 newform.aspx

How to render a link to the newform.aspx in SPFx

我创建了一个使用 DetailList 组件呈现列表内容的 Web 部件。 现在我想创建一个 link 到 NewForm.aspx,这样当用户点击它时就会被发送到新的项目表单。

link 需要是动态的。 Web 部件可以与不同的列表一起使用,所以我不能对 link.

进行硬编码

我该怎么做?

此致, 美国

您可以使用pnpJs获取列表形式url,示例代码供您参考。

sp.web.lists.getByTitle("MyList3").forms.select().filter("FormType eq 8").get().then((item: any) => {
      console.log(item[0].ServerRelativeUrl);
    });