Name parameter does not changes when changed in browser address bar
See original GitHub issue- Setted route with named parameter in routes.js:
import Post from "./pages/post.svelte";
export const routes = new Map();
routes.set("/posts/:id", Post);
- In Post component
<script>
export let params;
console.log(params.id);
</script>
{ params.id }
For example if I click on link “/posts/123” right in webapp - it works well, but if I change this link to “/posts/5” in browser’s address bar - ‘params.id’ still lasts as “123”
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Change the get parameters in the address bar in jquery
It is impossible to change the URL (anything before a hash tag) with jquery for security reasons. If you look closely, they are...
Read more >Vue Router: Reacting to parameter changes - Prismic
Vue Router doesn't re-render a component when a route parameter is changed. Here we discuss how to handle this issue in your Prismic...
Read more >Multi-Page Apps and URL Support - Dash Plotly
For module , the first argument, we give each of our pages a unique name (as these names are used as keys in...
Read more >Using a control with a parameter in Amazon QuickSight
In dashboards, parameter controls appear at the top of the data sheet, which contains a set of visuals. Providing a control allows users...
Read more >How View URLs Are Structured - Tableau Help
With the Embedding API v3, you no longer add parameters to view URLs to filter when ... let's take a close look at...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am not familiar with many other routers to this level so I can’t comment on their behavior fully. However, I don’t think this is about hash-based routing.
In Svelte 3, code inside the script block is executed only once, when the component is mounted the first time. To make code execute reactively, you can use the
$:
label.Now, when you change page from /posts/123 to /posts/456, the component is the same. So, the router does not un-mount and re-mount the component. This means that the code in the script block is not re-executed, unless you make the statements reactive by binding them to props.
The fact that the component is not un-mounted is a design decision: it minimizes the amount of re-renderings and so it gives best performance. It’s also consistent with the patterns of Svelte 3 (which recommend re-rendering only what’s updated and encourages using reactive statements). You can find a discussion on the topic in #148
Closing this for now as it seems to be working as intended. But feel free to comment further.
Still feel that routes with named parameter should act like other routes without it.
This is rithorical issue. Anyway thanks for your job!