preact-router icon indicating copy to clipboard operation
preact-router copied to clipboard

Use customHistory url instead of internal url in render if available

Open hesselbom opened this issue 8 years ago • 5 comments

Currently, when using 'history' module as customHistory, and blocking the history change, the internal state url in Router is still updated, even if window location isn't. This pull request aims to fix this.

hesselbom avatar Feb 07 '17 11:02 hesselbom

@hesselbom how are you blocking the history change? Just trying to set up a demo.

developit avatar Apr 06 '17 15:04 developit

/** @jsx h */
import { h, render } from 'preact'
import { Router, Link } from 'preact-router'
import createHistory from 'history/createBrowserHistory'

let history = createHistory()
history.block('Are you sure you want to leave this page?')

let ViewOne = () => <Link href='/two'>Go to view two</Link>
let ViewTwo = () => <Link href='/'>Go to view one</Link>

render((
  <Router history={history}>
    <ViewTwo path='/two' />
    <ViewOne default />
  </Router>
), document.body)

When trying to switch view but canceling in the prompt the view will update but the url won't.

hesselbom avatar Apr 06 '17 17:04 hesselbom

oh wow, I didn't know history.block was even a thing!

developit avatar Apr 06 '17 19:04 developit

Neither did I until I conveniently found it when needed for a very specific use case! ;)

hesselbom avatar Apr 06 '17 19:04 hesselbom

Just circling back to this - shouldn't this handler be getting fired to take block() into account? https://github.com/developit/preact-router/pull/140/files#diff-1fdf421c05c1140f6d71444ea2b27638R193

developit avatar Sep 08 '17 23:09 developit