在 Javascript 中使用 props.location.query 时如何提取字符串?

How do i extract the string when using props.location.query in Javascript?

下面是我如何获取从另一个组件发送的字符串。我想要实现的是能够将以下字符串存储在变量中。例如 var string1 应该获得 "user1" 而不是 {query:"user1"}

var string1 = this.props.location.query); 

console.log(string1);

当控制台日志执行时出现以下数据,这是我要检索的正确数据。

{query: "user1"}

该值似乎是一个对象,而不是字符串。尝试 this.props.location.query.query

this.props 大概看起来像这样:

{ props:
    { location:
        { query:
            { query: "user1" }
        }
    }
}