Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

setRouteLeaveHook double called #160

Closed
@ghost

Description

I'm having this issue when using redux simple router with setRouteLeaveHook on the context my routerWillLeave callback executes twice.

class MyComponent extends React.Component {
    constructor(props, context) {
        super(props, context);

        this.routerWillLeaveCallCount = 0;
    }
    componentDidMount() {
        this.context.router.setRouteLeaveHook(this.props.route, this.routerWillLeave.bind(this));
    }
    routerWillLeave(route) {
        console.log(route.action);
        if (this.hasUnsavedData() && this.routerWillLeaveEvenCallCount()) {
            return 'You have an unsaved data, are you sure you want to leave?';
        }
    }
    routerWillLeaveEvenCallCount() {
        return this.routerWillLeaveCallCount++ % 2 === 0;
    }

I see PUSH PUSH in my console log.
I cloned this repo https://github.com/freeqaz/redux-simple-router-example.git and upgraded it to react-router 2.0.0-rc4 and redux-simple-router 1.0.2 and confirmed it had the same issue.

When I run the example https://github.com/rackt/react-router/tree/master/examples/transitions it only fires once.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions