【问题标题】:when clicked on an href the new URL doesn't reload the page in Svelte单击 href 时,新 URL 不会在 Svelte 中重新加载页面
【发布时间】:2021-09-10 12:35:48
【问题描述】:

当用户单击 href 链接时,我目前正尝试将用户重定向到新页面。 问题是 url 本身确实发生了变化,但只有当我手动点击“重新加载”时,页面才会真正刷新并显示新数据。

我如何构建 href 链接:

resultString += "<a href='/edition/id=" + this.note['name'][i]['hkg:persKey'] + "'>";
resultString += this.note['name'][i]['#text'];
resultString += "</a>";

resultString 然后被推入一个数组并在另一个组件中正确读取。

问题是,当重定向时,url 中的 id 会明显改变并在 url 中更新,但页面不会重新加载。

例如: 在带有'id=xy' 的页面上,URL 是:'/edition/id=xy',并且在此页面上,会显示href '/edition/id=z'。 单击此 href 时,网址会明显更改为 '/edition/id=z',但页面不会重新加载。

有人知道怎么解决吗?

【问题讨论】:

  • 这个有什么更新吗?使用rel="external" 感觉就像在作弊。

标签: svelte sapper


【解决方案1】:

这是 Sveltekit 的一个功能。您可以尝试将rel=external 添加到您的链接中

<a rel="external" href="path">Path</a>

来源:https://kit.svelte.dev/docs

【讨论】:

    【解决方案2】:

    一旦我遇到同样的行为。我不记得是什么了,但我用 target="_self"

    治愈了它

    【讨论】:

    • 我正在使用&lt;a href="#my-element"&gt;Click&lt;/a&gt; 导航到本地元素,我注意到它每次都会刷新整个页面。显然,target="_self" 是您在内部链接时应该做的事情。我不知道我是怎么错过的。
    猜你喜欢
    • 2017-11-29
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-11
    • 2015-12-17
    • 2016-04-12
    相关资源
    最近更新 更多