reactjs - 更改 URL 但仅在刷新后加载组件
问题描述
应用程序.js
const App = () => {
return (
<div className='app-wrapper'>
<BgVideo />
<Header />
<Menu />
<Switch>
{routes.map((route, idx) => {
return route.component ? (
<Route
key={idx}
path={route.pathname}
exact={route.exact}
name={route.name}
render={props => (
<route.component {...props} key={new Date().getTime()}/>
)}
/>
) : null;
})}
<Redirect to={`/not-found`}/>
</Switch>
</div>
);
};
索引.js
import React from 'react';
import ReactDOM from 'react-dom';
import {Router} from 'react-router';
import App from './App';
import { history } from './_helpers';
ReactDOM.render(
<Router history={history}>
<App />
</Router>,
document.querySelector('#root')
);
** 不能按预期工作。它会在单击时更改 URL,但仅在强制刷新页面后才加载我的组件。<BrowserRouter>
工作正常,但我需要<Router>
因为<BrowserRouter>
忽略历史对象。
(我收到此警告消息:
Warning: <BrowserRouter> ignores the history prop. To use a custom history, use
import { Router } instead of
import { BrowserRouter as Router } .
)
PS 当我点击某个链接时,它第一次重定向到我的 Not-Found 页面,只有第二次它更改了 URL(不加载组件)。**
解决方案
推荐阅读
- mysql - 是否可以将表名派生为“NEW”。在 MySql 触发器中?
我有两张桌子
公司信息(符号、价格、父级)
观察列表(符号,观察值)
每当更新 COMPANYINFO 中的 PRICE 时,我需要从 COMPANYINFO 的 PARENTTABLE 字段中的表中获取最大值并更新 WATCHLIST 表的 WATCHVALUE。
我在COMPANYINFO中定义的触发器如下
BEGIN
- java - UML:方法图而不是类图?
- tensorflow - 为什么深度学习模型没有与加州房价数据融合?
- angular - Kendo UI 可排序组件不起作用
- python - 无论我尝试什么,都无法在 Selenium 中通过 Xpath 找到元素
- react-native - ScrollView React Native Horizontal 不工作
- c# - 如何像列表一样使用现有的数组?
- python - 如何使用 python 在 xlsx 表中插入文件对象?
- gatsby - 如何使流体Img组件小于其容器元素
- android-styles - 如何在android中更改概览按钮的背景颜色。(Android Studio)