【问题标题】:ReactJS Uncaught TypeError: match is undefinedReactJS Uncaught TypeError:匹配未定义
【发布时间】:2022-11-10 00:53:00
【问题描述】:

我使用 ReactJS 开发了一个 UI,路由器版本是 6。

我在 ReactJS 中使用了以下路由来传递我的参数,但我无法在类端获取参数,它给出的匹配错误未定义。

路由文件

<Route exact path="/productcategory/:category" element={<ProductCategoryPage />} /> 

产品类别页面文件

export class ProductCategoryPage extends Component {
constructor({match}){
    super();
    
    this.state = {
        Category: match.params.category,
        ProductData: []
    }
}
render () {
                 UI codes goes here. 

}
}

错误是匹配未定义

【问题讨论】:

    标签: reactjs react-router


    【解决方案1】:

    经过调整和搜索后,我发现答案如下,仅使用 Ajax 请求作为 blob 发送和接收。

     $.ajax({
        type: 'POST',
        url: $(element).attr('href'),
        data: data,
        xhrFields: {
            responseType: 'blob'
        },
        success: function(response){
            var blob = new Blob([response]);
            var link = document.createElement('a');
            link.href = window.URL.createObjectURL(blob);
            link.download = "report.pdf";
            link.click();
        },
        error: function(blob){
            console.log(blob);
        }
    });
    

    如果您想了解更多信息,请告诉我。 我希望这可以帮助其他人解决他们的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-02
      • 2016-09-24
      • 1970-01-01
      相关资源
      最近更新 更多