使用带有外部 URL 的 NavLink [英] using NavLink with external URL

查看:29
本文介绍了使用带有外部 URL 的 NavLink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

    <NavLink to="//student.lvh.me:8080/users/edit">
      <DropDownLink>Wiki</DropDownLink>
    </NavLink>

如何让导航链接与外部 URL 一起工作?我在控制台中收到以下错误:

how do I get navlink to work with external URLs? I get the following error in console:

未捕获的 DOMException:无法在History"上执行pushState":无法在具有 URL 的文档中创建具有 URLhttp://student.lvh.me:8080/users/edit"的历史状态对象来源 'http://localhost:3000' 和 URL 'http://localhost:3000/'.

有没有更好的方法来处理外部链接?

is there a better way to handle external links?

推荐答案

react-router 旨在在单页应用程序中进行路由,即在客户端处理路由.
当您想路由到外部页面时,例如在服务器端处理路由时,您可以使用普通的锚标记:

react-router meant to route in a Single Page Applications, i.e route is handled on the client side.
When you want to route to an external page e.g route is handled on the server side, you can use a normal anchor tag:

<a href="url.com">Wiki</a>

这篇关于使用带有外部 URL 的 NavLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆