Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loop in RouteStore.unregisterRoute method #148

Closed
wants to merge 1 commit into from
Closed

Fix infinite loop in RouteStore.unregisterRoute method #148

wants to merge 1 commit into from

Conversation

genbit
Copy link
Contributor

@genbit genbit commented Jul 30, 2014

Simple fix

@ryanflorence
Copy link
Member

woops! thanks.

@genbit
Copy link
Contributor Author

genbit commented Jul 30, 2014

@rpflorence no problem :)

Is any way to re-register routes? I want dynamically change routes of my application.

@ryanflorence
Copy link
Member

in theory ... we've never done it, you can have multiple "routers" on the page at once. Any time you React.renderComponent(routes, el) it'll register them. The RouteStore data is a single list of routes.

What's the use-case? My mediocre brain can't think of any reason not to declare every route your app responds to up front, primarily because you can potentially link to any part of your app from any other part of your app, how could you ever ensure you aren't linking to an unregistered portion of the app?

@genbit
Copy link
Contributor Author

genbit commented Jul 30, 2014

@rpflorence for example I want to enable/disable some routes, when user enable/disable some feature in settings, without page refresh.

React.renderComponent(routes, el);

Yes, but looks like routes only are registered on Routes.componentWillMount and they will not be re-registered on render.

I managed to hack it, using the following code:

        RouteStore.unregisterAllRoutes();
        React.Children.forEach(this.getRoutes(), function (child) {
            RouteStore.registerRoute(child);
        });

and small hack in Routes.match method.

but not sure if it's good solution...

https://github.com/genbit/react-router/commit/e3ca7c7221b37c404c66963fa45c6a5470aabc30

@ryanflorence
Copy link
Member

why not have your willTransitionTo hooks check some store to see if they are disabled and then redirect? If the user has these routes in their history and use the back button, or saves a link and comes back, I think you'd want to handle it?

@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants