javascript - ReactJS:从一个页面导航到另一个页面
问题描述
我又创建了两个页面,第一个是主页(我可以进入这个页面),第二个页面是一个创建表单(我不能去这里!)
我的文件夹结构:
application:
> application.tsx
> application-update.tsx
> index.tsx
// there I have created a new folder (LegacyFolder) with the page
>LegacyFolder
>>index.tsx
>>applicationLegacy.tsx
>>applicationLegacy-update.tsx
我在 LegacyFolder/index.tsx 中复制了(显然有一些更改)我的 application/index.tsx
import ApplicationLegacy from './applicationLegacy';
import ApplicationLegacyUpdate from './applicationLegacy-update';
const Routes = ({ match }) => (
console.log('match ', match),
(
<>
<Switch>
<ErrorBoundaryRoute path={match.url} component={ApplicationLegacy } /> // (I can go there)
<ErrorBoundaryRoute exact path={`${match.url}/new`} component={ApplicationLegacyUpdate } /> // I can't go there
</Switch>
</>
)
);
export default Routes;
现在从我的菜单中我可以进入 ApplicationLegacy。
在 ApplicationLegacy 里面,我有一个按钮可以进入 ApplicationLegacyUpdate 页面:
<Link to={`${match.url}/new`} className="btn btn-primary jh-create-entity" id="jh-create-entity" data-cy="entityCreateButton">
<FontAwesomeIcon icon="plus" />
<Trans i18nKey="applicazione.create">{'applicazione.create'}</Trans> Application
</Link>
当我单击此处时,我的 url 更改为/applicationLegacy/new
但页面没有更改。
我能怎么做?
解决方案
我想如果您将 prop 精确添加到第一个名为 ErrorBoundaryRoute 的组件中,该组件负责显示名为 ApplicationLegacy 的组件,我想您可以解决问题。
推荐阅读
- r - 使用 github_install 安装 r 包时出现 processx 错误是什么意思?
- unit-testing - 如何在 Play 框架中为 Ebean 编写单元测试
- php - 添加可与 WC Vendors 插件一起使用的自定义 Woocommerce 产品状态
- c++ - if 语句的这种用法会导致未定义的行为吗?
- python - 如何将屏幕输出的结果保存到 python 上 2 列中的 csv 文件?
- javascript - 加载 HTML 元素时是否可以调用函数?
- vbscript - 在 VBS 中按名称而不是 id 选择项目
- javascript - 如何使用导航请求模式?
- node.js - node.js 中静态文件的 Pah 引用
- reactjs - npm run build 不使用代理