]> git.openstreetmap.org Git - nominatim-ui.git/blob - src/components/PageLink.svelte
Svelte5: runes, events and @render context (#289)
[nominatim-ui.git] / src / components / PageLink.svelte
1 <script>
2   import { refresh_page } from '../lib/stores.js';
3
4   let {
5     page,
6     text,
7     text_snippet,
8     params_hash = {},
9     extra_classes = '' } = $props();
10
11   function handleClick(e) {
12     e.preventDefault();
13     e.stopPropagation();
14     refresh_page(page, new URLSearchParams(params_hash));
15   }
16
17   const href = $derived.by(() => {
18     const param_str = new URLSearchParams(params_hash).toString();
19     return page + '.html' + (param_str ? '?' : '') + param_str;
20   });
21 </script>
22
23 <a onclick={handleClick} href={href} class={extra_classes}>
24   {#if text_snippet}{@render text_snippet()}{:else}{text}{/if}
25 </a>