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.

Reflecting UI changes to the route

See original GitHub issue

Sometimes this would be grate to have UI state in route. for example in a list that is filtered with some check boxes. When the user clicks on a checkbox I like the route to change so that the user is able to share that route or bookmark it. I don’t want to use # since Google will ignore it. currently if I do something like this:

import history from './history';
history.replace('/itemts/filter=discount,new');

It will change the position of my scroll. How can I implement such a thing?

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
frenzzycommented, Aug 18, 2017
let previousLocation = history.location;
function onLocationChange(location) {
  // here you have both location and previousLocation
  previousLocation = location;
}
1reaction
frenzzycommented, Aug 18, 2017

You need to decide in which case you don’t need to scroll. For example you may skip scrolling if path wasn’t changed or if history.replace were used.

if (!(previousLocation.pathname === location.pathname && action === 'REPLACE')) {
  window.scrollTo(scrollX, scrollY);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Reflect changes of same Vue Component to different routes
1 Answer 1 · Global Event Bus - keep the active tab in a global EventBus state that will also listen to changes,...
Read more >
Overview of UI-Router React and comparison with React Router
It's a drop-in utility that lets you visualize the state tree and transitions of your UI-Router application. It's written in React, and works...
Read more >
Using UI-Router for better React routing | by Scott Carmichael
To trigger a transition; state names are used, not urls. The easiest way to change state is using the UISref component, which is...
Read more >
push a new route only triggers URL change but not location ...
set up the connected-react-router as doc. but it only update the url rather than the location object when yield put(push( /somewhere )) in ......
Read more >
Change And Its Detection In JavaScript Frameworks
This can happen when the user interacts with the UI, or when something else happens in the world that updates the data. The...
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