使用NextJS将道具传递到按钮中的URL

发布于 2025-02-09 06:56:43 字数 843 浏览 3 评论 0 原文

这是针对NFT薄荷Dapp。我的Web应用程序中有4个不同的NFTS铸造页面,并在Nextjs构建中,每个nfts应用程序都被铸造出来,我的按钮出现了一个按钮,上面显示“ Opensea上的视图”。

当您单击此按钮时,我希望它可以打开一个新标签,并将您发送到单个列表中的链接,看起来像:

“ testnets.opensea.io/assets/mumbai/0xB636C1A63C3B092A7C74304B1947B0162D08A1E4/0”。

0xb63 ...是合同地址, / /0是代币。我将代币保存在数据文件中,将其传递到我的应用程序的其他领域。但是我不知道如何将其纳入URL。

这是我到目前为止所拥有的:

  const url =
    "testnets.opensea.io/assets/mumbai/0xb636c1a63c3b092a7c74304b1947b0162d08a1e4/{props.id}";
  window.open(url, "_blank");
};

但是它不起作用。对此的任何帮助都是感谢。这是我的回购中指向该行的链接:

This is for an NFT minting dAPP. I have 4 different NFTs minting pages in my web app built with nextjs, and after each one is minted I have a button appear that says "View on OpenSea".

When you click on this button, I'd like it so that it will open a new tab and send you to the individual listing to a link that looks like:

"testnets.opensea.io/assets/mumbai/0xb636c1a63c3b092a7c74304b1947b0162d08a1e4/0".

0xb63... being the contract address, and /0 being the tokenID. I have the tokenId saved in a data file, passing that prop into other areas of my app. But I can't figure out how to get it into a URL.

This is what I have so far:

  const url =
    "testnets.opensea.io/assets/mumbai/0xb636c1a63c3b092a7c74304b1947b0162d08a1e4/{props.id}";
  window.open(url, "_blank");
};

But it doesn't work. Any help on this is appreciate. Here is a link to that line in my repo: https://github.com/redbrickmedia/rdbrck-nft/blob/0872e3bbd69ae12ff2b2d5532d5e0da0c78663fa/components/Buttons.js#L52

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倒带 2025-02-16 06:56:43

刚刚尝试了您的代码并正常工作,但我的浏览器会自动阻止编程弹出窗口。我建议用< a href =“ url” target =“ _ blank”> 替换按钮,使其看起来像您的填充顿。

也许是因为您的道具没有插值,请尝试以下操作:

function YourComponent(props) {
  const targetUrl = `https://testnets.opensea.io/assets/mumbai/0xb636c1a63c3b092a7c74304b1947b0162d08a1e4/${props.id}`

   return (
      <a href={targetUrl}> Click here</a>
   )
}

Just tried your code and works fine but my browser automatically blocks programmatic popups. I'd suggest to replace the button with an <a href="url" target="_blank"> and make it look like your FilledButton.

Maybe it's because your prop is not getting interpolated, try the following:

function YourComponent(props) {
  const targetUrl = `https://testnets.opensea.io/assets/mumbai/0xb636c1a63c3b092a7c74304b1947b0162d08a1e4/${props.id}`

   return (
      <a href={targetUrl}> Click here</a>
   )
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文