javascript - 是否可以使用 react-router-dom 动态导航不同的本地主机?
问题描述
我有一个 Web 应用程序,目前我正在通过localhost:3002
. 在此 Web 应用程序中,我使用来自此卡的卡片,reactstrap
并且在此卡片上有一个我要从中导入的链接 我import { Link } from 'react-router-dom';
正在使用此链接转到应用程序的特定详细页面。
问题:我同时运行另一个应用程序,localhost:5000
它是一个登录系统。从Link
我描述的卡片中,我可以使用“项目规格”下方的按钮转到其他本地主机为 5000 的应用程序吗?
在代码片段下方:
import React from 'react';
import { Card, CardTitle, CardSubtitle, CardText, CardBody, CardImg } from 'reactstrap';
import { Link } from 'react-router-dom';
<CardTitle>
<h3 className="thick">{ship.name}</h3>
</CardTitle>
<CardText>
<h6>Project Details</h6>
<p>For a description of the project view the specification included</p>
</CardText>
<div class="btn-toolbar">
<Link to="/localhost:5000/login" className="btn btn-primary mr-3">
Go to Specs
</Link>
<Link to={`/vessels/${ship.slug}`} className="btn btn-primary">
Go to vessels
</Link>
</div>
到目前为止我做了什么:
1)从这篇文章中,我能够正确设置react-router-dom
并且实际上工作正常。
2)我试图将它链接到另一个localhost:5000
,因为当我将它链接到我的应用程序上已经存在的特定页面时,只需键入即可<Link to="/localhost:5000/" className="btn btn-primary mr-3">
,不幸的是它不起作用。
3)我也遇到了这个问题,这对于理解如何浏览页面而不是通过不同的本地主机很有用
解决方案
react-router-dom 的 Link 组件旨在链接到应用程序内的路由。要外部链接,您可以使用 HTML 'a' 标签: <a href="http://localhost:5000" className="btn btn-primary mr-3">
更多信息和其他可能的解决方法:
推荐阅读
- android - 如何从我在 android xml 文件中创建的按钮获取输入
- python-3.x - 如何使用 Python 从图像中读取文本和文本颜色?
- c++ - shared_ptr 构造函数参数是否应该按值传递
- spring - Spring Boot REST 未显示或链接到 RESTController 页面/类
- node.js - 在 Jenkins 管道中执行 npm 脚本(带变量)
- triggers - Ionic3 LocalNotification 每天特定时间
- javascript - 使用 Javascript 激活 Foundation 6 Reveal 模式
- qt - 在 QTreeWidgetItem 中隐藏 QComboBox
- javascript - 如何通过点击id打开模态
- kubernetes - JupyterHub setup- CrashLoopBackOff 中的 Kubernetes hub pod