Skip to content

(HashHistory not supported) Changing URL in browser and clicking confirm doesn't navigate #36

Open
@mcupito

Description

@mcupito

When I change the URL directly in the browser, I am seeing that my page is not actually navigating upon confirm of the action. I've briefly debugged and saw that the _state.action is POP when this occurs -- unsure if I can manually try to make this PUSH and see what happens.

Scenario:

On test.com/x
Type in test.com/y
Pop-up appears
Click Yes, Leave the Page (onConfirm)
Prompt closes and nothing else happens, but the URL stays the same

I am using React with Redux, along with React Router.

Here's the implementation :

import ConfirmModal from "../Confirm/Modal";

class NavigationBlocker extends React.Component {
    constructor(props) {
        super(props)
	}
	
	render() {
		return (
				<NavigationPrompt when={this.props.canSave}>
					{({ onCancel, onConfirm }) => (
						<ConfirmModal
							titleText={this.props.title}
							onCancelClicked={onCancel}
							onActionClicked={onConfirm}
							visible={true}
							cancelLabel={'No, keep working'} 
							actionLabel={'Yes, leave anyway'}
						>
							<p>{'Your changes were not saved. Do you still want to leave?'}</p>
						</ConfirmModal>
					)}
				</NavigationPrompt>
		);
	}
}

The ConfirmModal has a decent amount of code in it, but it doesn't truly do anything except render what was passed in and call the props as actions :

<Button type="button"  onClick={this.testActionClick} >
	<strong>{this.props.actionLabel || 'OK'}</strong>
</Button>

<a type="button"  onClick={(e) => this.cancelClicked(e, this.props.onCancelClicked)}>
	<strong>{this.props.cancelLabel || 'Cancel'}</strong>
</a>

Sidenote: I did not implement this code, but noticed this behavior and have since taken over trying to resolve it. I am aware that this implementation doesn't use any fancy comparison of location or anything that doesn't ship out of the box, so it could be a lacking implementation.

Thanks for your time!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions