Sveltekit页面更改会在页面底部添加HTML。

huangapple go评论61阅读模式
英文:

Sveltekit page change adds HTML at bottom of page

问题

我有一个 Sveltekit 网络应用程序,你可以在这里找到。

你也可以在这里找到完整的代码。

我的问题是:当我改变页面时,新页面会附加到当前页面的末尾。当我刷新时,旧页面会消失。

这个问题与这个非常相似,但我没有使用任何加载指示器,并且提出的解决方法在我的情况下没有起作用。

是否有人知道我做错了什么?

包版本:

"@sveltejs/kit": "^1.22.1",
"svelte": "^3.58.0",
"@auth/sveltekit": "^0.3.3",

/+layout.svelte

<script lang="ts">
 ... imports
</script> 

<div class="flex flex-col h-screen">
  <Drawer>
    <AvatarDropdown slot="user" />
    <div class="grow h-full" slot="content">
      <slot />
    </div>
  </Drawer>
</div>

/dashboard/+layout.svelte

<script>
  const user = $page.data.session?.user;
</script>

{#if user}
  <slot />
{:else}
  请登录
{/if}

/dashboard/+page.svelte

<script>
  import { onDestroy } from "svelte";
</script>
<div
  class=""
  out:fade={{ duration: 0 }}
>
内容
</div>
英文:

I have a Sveltekit Web Application that you can find here

You can also find the full code here

My problem is the following: When I change the page, the new page gets appended to the end of the current page. When I refresh, the old page goes away.

The problem is very similar to this one, but I do not use any loading indicator, and the proposed fixes did not work in my case.

Would anyone know what I am doing wrong?

Package versions:

&quot;@sveltejs/kit&quot;: &quot;^1.22.1&quot;,
&quot;svelte&quot;: &quot;^3.58.0&quot;,
&quot;@auth/sveltekit&quot;: &quot;^0.3.3&quot;,

/+layout.svelte

&lt;script lang=&quot;ts&quot;&gt;
 ... imports
&lt;/script&gt; 

&lt;div class=&quot;flex flex-col h-screen&quot;&gt;
  &lt;Drawer&gt;
    &lt;AvatarDropdown slot=&quot;user&quot; /&gt;
    &lt;div class=&quot;grow h-full&quot; slot=&quot;content&quot;&gt;
      &lt;slot /&gt;
    &lt;/div&gt;
  &lt;/Drawer&gt;
&lt;/div&gt;

/dashboard/+layout.svelte

&lt;script&gt;
  const user = $page.data.session?.user;
&lt;/script&gt;

{#if user}
  &lt;slot /&gt;
{:else}
  Please log in
{/if}

/dashboard/+page.svelte

&lt;script&gt;
  import { onDestroy } from &quot;svelte&quot;;
&lt;/script&gt;
&lt;div
  class=&quot;&quot;
  out:fade={{ duration: 0 }}
&gt;
Content
&lt;/div&gt;

答案1

得分: 1

这个旧问题所描述,转换可能会破坏您的用户界面。

|local添加到您的转换中将解决这个问题,就像这样:

&lt;div out:fly|local={{ y: -200, duration: 500 }}&gt;
    ...
&lt;/div&gt;

另一个"修复"方法是根据这里的描述,在您的链接中设置data-sveltekit-reload,但显然当用户点击链接时您可能不希望重新加载页面。

英文:

As described in this old issue, transitions can mess up your UI.

Adding |local to your transition will solve the problem, like this:

&lt;div out:fly|local={{ y: -200, duration: 500 }}&gt;
    ...
&lt;/div&gt;

Another "fix" can be to set data-sveltekit-reload in your link as described here, but obviously you may not want to reload the page when a user clicks on the link.

huangapple
  • 本文由 发表于 2023年7月10日 18:34:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76652898.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定