-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Anchor with #hash not showing :target CSS after history.back() #10550
Comments
This is what I'm using to work around it without reloading the page.
|
This seems to be a limitation of client-side routing / rendering. The browser navigates to the new URL but cannot find the element with the corresponding id as it has not been rendered through javascript yet. You can observe a similar behaviour when navigating from I'm not sure what the solution here is. Adding If you prefer a hacky alternative, #10550 (comment) and using an empty hash Related #3177 (with some good findings inside the PR and issues linked) |
Now that <script lang="ts">
import { page } from '$app/stores';
</script>
<p id="secret-code" class:hidden={$page.url.hash !== '#secret-code'} class="target:block">
Hidden Message Block
</p>
<a href="#secret-code">Show Message</a> Not that this REQUIRES JavaScript to work.
<!-- ShowOnTarget.svelte -->
<script lang="ts">
import { page } from '$app/stores';
export let id: string;
</script>
<div {id} class:hidden={$page.url.hash !== `#${id}`} class="target:block">
<slot></slot>
</div> |
Describe the bug
/#target
/temp
/#target
and the#target:target
styles are not shown.In this state, clicking
<a href="#target">
should show#target:target
styles, but it does not.Reproduction
https://stackblitz.com/edit/github-ymws75?file=src%2Froutes%2F%2Bpage.svelte
System Info
Severity
annoyance
Additional Information
<a href="#target" data-sveltekit-reload>
fixes the:target
CSS issue.The text was updated successfully, but these errors were encountered: