英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论