使用匹配不起作用从网址反应提取参数

问题描述 投票:0回答:1

我正在尝试访问URL中的参数但不是为了获取它们。 console.log(User);给了我undefined。网址看起来像这个http://localhost:3000/data/Auto/90293/22/Female

错误TypeError:无法读取未定义AT属性return <h1>Hello {match.params}!</h1>的属性'params'

class Customers2 extends Component
{
    constructor() {
        super();
    }

    render() {
        const User = ({ match }) => {
            return <h1>Hello {match.params}!</h1>
        };
        console.log(User);
        console.log("Bhai Print hoja");
        console.log(window.location.href);
        return (
                <div>
                    <User/>
                    <h1>bhaui bhai</h1>
                </div>
        )
    }
 }
reactjs
1个回答
0
投票
render() {
    var User = function( match ){
      {console.log(match)}
      return <h1>Hello {match.params}!</h1>
    };
    var match = {
      params:"ho gea"
    }
    console.log(User);
    console.log("Bhai Print hoja");
    console.log(window.location.href);
    return (
      <div>
      {User(match)}
        <h1>bhaui bhai</h1>
      </div>
    )
  }
}

我想这就是你想要的代码。您将传递匹配对象,然后将其提供给函数User,它将返回您的标题。

© www.soinside.com 2019 - 2024. All rights reserved.