您何时设置locationURL字符串而不是设置location.href?
location = "http://www.stackoverflow.com";
VS
location.href = "http://www.stackoverflow.com";
我正在尝试在我的Angular 2应用程序中设置一个功能,该功能将使用用户的默认电子邮件客户端发送一封电子邮件,其中包含一些预先填充的信息:
sendEmail() {
    this.title = document.title;
    this.title = this.title.replace("&", "-");
    window.location = "mailto:?body=" + this.title + " - " + window.location + "&subject=I thought this link might interest you.";
}
但我遇到了一个问题,我收到了一个错误:
无法分配到"位置",因为它是常量或只读属性.webpack:编译失败.
我到目前为止看到的例子都描述了这样做,使用"window.location",那么我该如何解决这个问题呢?
这听起来好像以前肯定有人问过,但我只能在 react native 中找到如何做到这一点,但在正常 react for web 中我找不到它是如何做到的。最好不要使用需要样式化的标签或链接标签。
这里有一些代码来说明我想要做什么:
const onClickMailtoHandler = () => {
    //TODO: open default e-mail client e.g. via mailto link with text from (state) variable as body
}
<Button onClick={onClickMailtoHandler}>Send E-Mail</Button>
以下是如何在 HTML 中创建 mailto 链接:
<a href="mailto:max.mustermann@example.com?body=My custom mail body">E-Mail to Max Mustermann</a>