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

BUG: History.push() allows navigation with prompt #49

Open
Nikodermus opened this issue Apr 4, 2019 · 5 comments
Open

BUG: History.push() allows navigation with prompt #49

Nikodermus opened this issue Apr 4, 2019 · 5 comments

Comments

@Nikodermus
Copy link

"react-router-navigation-prompt": "^1.8.5",

BUG

Redirection made through history.push() is not taken in account for the prompt to be triggered and allows redirection in the end.

Steps to reproduce:

  • Given a component which has access to the history obj (Like using withRouter HOC)
  • Create a prompt with a when={true}
  • A button which onClick={()=> props.history.push('/')}
  • It will redirect without triggering the prompt

Expected behavior:

Prompt should be triggered even when the router change is made with the history.push function.

The button click resolves a redux action which then triggers the history.push(), maybe it has to do?

Additional Info

├─┬ docz@0.13.7
│ ├─┬ docz-core@0.13.7
│ │ └─┬ @mdx-js/loader@0.16.8
│ │   └─┬ @mdx-js/tag@0.16.8
│ │     └── react@16.8.3  extraneous
│ ├── react@16.8.3 
│ ├── react-router@4.3.1 
│ └─┬ react-router-dom@4.3.1 
│   └── react-router@4.3.1  deduped
├─┬ docz-theme-default@0.13.7
│ ├─┬ @emotion/styled@10.0.7
│ │ └─┬ @emotion/styled-base@10.0.7
│ │   └── react@16.8.3  extraneous
│ ├── react@16.8.3 
│ └─┬ react-live@1.12.0
│   └── react@16.8.3  extraneous
├─┬ docz-theme-hydrate@1.5.1
│ ├─┬ docz@0.12.17
│ │ ├── react@16.8.3  deduped
│ │ ├── react-router@4.3.1  deduped
│ │ └─┬ react-router-dom@4.3.1 
│ │   └── react-router@4.3.1  deduped
│ └── react@16.8.3 
├── react@16.6.0 
├─┬ react-ga@2.5.3
│ └── react@16.8.3 
├─┬ react-router-dom@4.2.2 
│ └── react-router@4.3.1  deduped
└── react-router-navigation-prompt@1.8.5 
@ZacharyRSmith
Copy link
Owner

Thanks for the issue, @Nikodermus . Unfortunately, I'm not sure when I'll be able to look at it. Would you please PR a fix?

@Pau1fitz
Copy link

@Nikodermus @ZacharyRSmith I am seeing the same, I think it is only when you push to '/' - props.history.push('/'), at least this is the only route I am seeing this behaviour.

If I do props.history.push('/'test) there is no problem. @Nikodermus can you check if it works if you don't use '/' but instead navigate to a different route?

@Nikodermus
Copy link
Author

Indeed, this is working fine with routes different to '/', do you maybe a baseName different to '/' in your app @Pau1fitz ?

@Joachimzeelmaekers
Copy link

@Nikodermus Could you try using
<NavLink to="/"> Back to overview </NavLink>
component instead of a button?

@ohelixa
Copy link

ohelixa commented Jul 1, 2020

Any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants