我在访问父组件的param id时遇到了问题。我知道属性是从父组件传递到子组件的,所以例如Dashboard组件可以访问id,但是侧边栏组件不能。如上所述,有没有任何方法可以为侧边栏提供该id,以便在选择选项卡时它可以适当地路由。 Signin.js case 'server':
props.history.push('/profile');
break;
case 'manager':
if (user.linkedRestaurants.length > 1) {
我有一个共同的成功组件,并通过导航路径呈现该组件。
SuccessComponent.jsx
var pageTitle;
const SuccessComponent = (props) => {
pageTitle = props.location.state.title;
return(
<> jsx code here </>
)
}
//This title needs to be dynamic, not getting props here hence took var pageTitle but getting undefi
我正在编写一个单元测试来模拟单击按钮。按钮的onClick方法引用了使用props.history.push('/)加载另一个页面的方法。模拟可以工作,但开玩笑说,它不能读取属性推送,因为历史是未定义的,这使得测试到fail.How,我可以添加props.history,而单元测试,.What,我做错了。
这是测试文件
import React from 'react';
import Landing from '../Components/Landing/Landing';
import configureStore from 'redux-
我想从一个组件重定向到另一个组件,并在它们之间传递道具。
function MyFirstComponent({survey}) {
....
// There is a button that triggers the below if clause. The redirect works but it seems the state is not sent.
if (surveyPage === true) {
return <Redirect to={{
pathname: '/detail',
我已经把道具传给了这个组件,这个接口可以很好地与location: any配合使用。但现在我还想传入props:RouteComponentProps,这样我就可以通过编程方式更改视图。我得到的错误是.. Type '(props: RouteComponentProps<{}, StaticContext, any>) => Element' is not assignable to type 'FunctionComponent<propsInterface>'. Types of parameters 'prop