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.

Page doesn't re-render when URL parameter changes

See original GitHub issue

How to reproduce:

  • configure a route with a parameter, e.g. item/:itemId
  • navigate to a valid route, e.g. item/7
  • change the itemId parameter value, e.g. item/8, in the browser address bar and hit enter

Expected result:

  • browser should fire a hashchange event
  • router should replace the page content for item 7 with the content of item 8

Actual result:

  • browser fires a hashchange event ✔️
  • router doesn’t replace the page content (still showing item 7) ❌

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
crazedViccommented, Jun 5, 2020

Thanks for pointing me in the right direction. Took me a while still to get it working but I got there. For others that end up here, who maybe are as new at svelte as I am, this is what i did to get it working:

import { location } from 'svelte-spa-router';

then in the script i put this line:

$: getBookings($location);

this is the fetch function:

const getBookings = async (location = null) => {
        status = location.split('/')[2];
        fetch(url + 'shifts/' + status, options)
                .then(res => {
                    if (res.ok) {
                        res.json().then(json => {
                            bookings = json.data;
                        });
                    }
                    else{
                        statusText = "Error loading bookings"
                    }
                })
                .then(res => console.log(res));
    }

the format of the url for my app is:

/Bookings/{{status}}
2reactions
duduindocommented, Jun 7, 2020

@crazedVic Thank you!

Easy example:

<script>
  import { querystring } from 'svelte-spa-router'

  $: load($querystring)

  function load(value) {
    console.log("Re-call", value)   
  }
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why React-router doesn't re-render the page ... - Stack Overflow
If Details component is linking to itself, i.e. the route rendering it, this means the route path is already matched and rendering Details...
Read more >
Component not re-rendered when changing url param #27
Try passing the route parameter id as a prop ; If you need your component to be fully unmounted and remounted, you can...
Read more >
Page is not re-rendering after URL parameter changed - Telerik
Hi, I'm using "nav-link" to go to page: @page "/orders" I'm also using Parameter which tells me what type of order to be...
Read more >
How to rerender components when vue router params ...
In this lesson, we learn how to re-render components when Vue Router params of the same route changes. We learn about the special...
Read more >
(Router) URL changes but the page does not re-render : r/reactjs
I am new to react and react-router, so please go easy on me. I am trying to implement router in my Todo List...
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