question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Name parameter does not changes when changed in browser address bar

See original GitHub issue
  1. Setted route with named parameter in routes.js:
import Post from "./pages/post.svelte";
export const routes = new Map();
routes.set("/posts/:id", Post);
  1. 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:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ItalyPaleAlecommented, Oct 30, 2020

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.

0reactions
azakostcommented, Oct 30, 2020

Still feel that routes with named parameter should act like other routes without it.

This is rithorical issue. Anyway thanks for your job!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found