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.

Clear page when transitioning to same route.

See original GitHub issue

So I have these routes

var routes = (
    <Route handler={App}>
        <Route name="login" handler={Login}/>
        <Route name="logout" handler={Logout}/>
        <Route name="dashboard" path="/" handler={Dashboard} />
        <Route name="user" path="/users/:id" handler={ShowUser} />
    </Route>
);

I use the Link component to transfer between Dashboard and ShowUser which works fine. When I go from one User to another User(ie: users/1 to users/5) from the users page, the page doesn’t re render the way I would suspect. I’ve tried using componentWillRecieveProps but it doesn’t seem to re render everything. Plus I get Uncaught Error: Invariant Violation: processUpdates().

Is there a way to blow out the page and load the page like I was coming from another route? Thanks!

Edit: I solved this by using an isLoaded state and render the main page entry point when that’s set. I still would like to hear any comments about this. Thanks!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
gaearoncommented, Jan 2, 2015

@VinSpee @drewhamlett

You should handle it in componentWillReceiveProps in your handlers.

// SomeHandler.js
var SomeHandler = React.createClass({
  componentWillReceiveProps: function (nextProps) {
    if (this.props.params.id !== nextProps.params.id) {
      // do something to update your state
    }
  },

  // ...
})

// index.js
router.run(function (Handler, state) {
  React.render(<Handler params={state.params} />, document.body);
});
1reaction
gaearoncommented, Jan 2, 2015

@VinSpee

Minimizing state is good but you can have componentWillReceiveProps as I suggested in the component that has currentUser in state already.

Kind of like this. In your case,

getInitialState() {
  return this.getStateFromStores(this.props);
},

getStateFromStores(props) {
  return {
    currentUser: UserStore.get(parseInt(props.params.userId))
  };
},

componentWillReceiveProps(nextProps) {
  this.setState(this.getStateFromStores(nextProps));
}

Does this make sense?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Clear page when transitioning to same route. #572 - GitHub
I use the Link component to transfer between Dashboard and ShowUser which works fine. When I go from one User to another User(ie:...
Read more >
Ember - Transition to same route with same model
Save this question. Show activity on this post. I have a left tree list, and each item in the list opens same route...
Read more >
Apply and clear page transitions in InDesign - Adobe Support
In the Pages panel, select the spread from which you want to clear the transition, and then choose None from the Transition menu...
Read more >
How to create page transitions with React Router - YouTube
Learn how to create page transitions with React and React Router.Have you ever tried to create page transitions with React?
Read more >
Router tutorial: tour of heroes - Angular
This guide describes development of a multi-page routed sample application. Along the way, it highlights key features of the router such as: Organizing...
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