前往保留的上一个组件

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

svelte goto remain previous component

问题

你好,我有一个包含URL为categories/{slug}的分类页面和一个/products页面,在这两个页面上,我加载了相同的组件。但是,在/products页面上,当我点击一个分类项并跳转到categories/{slug}时,我会在页面上看到2个组件(之前的组件仍然存在)。

我使用goto()方法更改了URL,但我不想刷新页面。

我尝试在布局中使用{#key},但它不起作用。

英文:

hi I have a categories pages with url categories/{slug} and a /products page in this 2 page I load a same component but when in /products page I click in a category item and goes to categories/{slug} I see 2 component in my page (previous component remain)

I change the url with goto() and I don't want to refresh the page.

I tried {#key} in layout but it's not working.

答案1

得分: 1

I tried {#key} in layout but it's not working.
这似乎是问题所在。当您在布局中添加组件时,它将出现在使用该布局的所有页面上。
您的方法可能有点问题,要么将组件添加到两个路由页面,要么添加到布局中。没有更多代码很难判断。

英文:

> I tried {#key} in layout but it's not working.

This sound like the problem. When you add a component to the layout it will appear in any pages that use the layout.

Your approach is probably just off, either add the component to the two route pages or only the layout. Hard to tell without more code.

huangapple
  • 本文由 发表于 2023年6月19日 15:48:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76504604.html
  • svelte
  • sveltekit

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

确定