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.

Params don't change when changing URL

See original GitHub issue

Describe the bug

I have these routes in my Router with HashIntegration:

<Routes>
        <Route path="" component={Home} />
        <Route path="docs/:doc" component={Docs} />
</Routes>

Home just says home and Docs displays Doc: {and here the :doc from useParams().doc}

When i load the page at localhost:3000/#/ it works fine. Now when i change the url to localhost:3000/#/docs/cool and hit enter it also switches and shows Doc: cool. But when i change to url to localhost:3000/#/docs/notworkingsad it still shows Doc: cool and only when i hold shift and then refresh to rebuild the connection it shows Doc: notworkingsad.

so in short:

when using hashrouter and changing page, works fine. when then changing an parameter it doesnt reload the component with the parameter until i reload the whole page with a new connection.

Your Example Website or App

See code in Describe the bug section

Steps to Reproduce the Bug or Issue

See code in Describe the bug section

Expected behavior

Also “reload” the component with the new parameters like when switching the page.

Screenshots or Videos

No response

Platform

  • OS: [Windows]
  • Browser: I tested: [Chrome, Firefox]
  • Version: [OS, Browsers and all node packages are on the newest version]

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ryansolidcommented, Sep 8, 2022

Yeah don’t destructure from useParams

Try

const params = useParams();

href={`/l/${params.lid}${item.path}`}

The properties on the object are reactive so they need to be accessed under a tracking scope.

0reactions
tendantcommented, Nov 28, 2022

Had same issue. Below documentation is very useful:

https://github.com/solidjs/solid-router#useparams

const params = useParams();

// fetch user based on the id path parameter
const [user] = createResource(() => params.id, fetchUser);

The fetchUser won’t be triggered if use params.id directly when createResource().

const params = useParams();

// Won't work!
const [user] = createResource(params.id, fetchUser);
Read more comments on GitHub >

github_iconTop Results From Across the Web

React Router does not update component if url parameter ...
It is not updating the view if the url changes parameters. For example, navigating from /users/454545 to /teams/555555 works as expected.
Read more >
Vue Router: Reacting to parameter changes - Prismic
Vue Router offers a link component that will change the URL in the user's address bar. However, changing the URL alone doesn't change...
Read more >
Vue router - URL does not react to params change
The URL is '/profile/user2'. Now I click the router-link on the navbar and get to my own profile. The username parameter changes to...
Read more >
Component not re-rendered when changing url param #27
Component not re-rendered when changing url param #27 ... I've set the router option to be strictQueryParams: true but nothing change.
Read more >
Navigate to a URL with Query Strings (Search Params) in ...
React Router has a useSearchParams hook to help us read or update the query string of a route that's active, but it doesn't...
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