blackmind
blackmind

Reputation: 1296

React Router: Transition without window.location

I have an application that uses React Router. The application creates a new item by calling the createPage action, which calls my RefluxJS store and makes a call to an API endpoint. Once that API call returns and is successful I pass the new page object to the pageCreated action. Within my onChanged even in the JSX file I want to transition to a route based on a property of the page without refreshing the page, but I am at a loss on how to do it.

I want to do something similar to window.location = /pages/1234 where 1234 comes from the page object returned by the API.

I have tried Router.transitionTo('/ua-manager/pages/' + options.alias);, but that returns as not a function. How can I achieve this transition without using window.location?

Upvotes: 0

Views: 187

Answers (1)

Henrik Andersson
Henrik Andersson

Reputation: 47172

#transitionTo exists on the Router object instance and not the class so access it through this.context.router and it'll work or just add the Navigation mixin.

this.context.router.transitionTo('/ua-manager/pages' + options.alias);

Upvotes: 1

Related Questions