forked from redfin/react-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose new convenience function:
navigateTo
This is a much nicer interface for kicking off a client transition. This closes redfin#114.
- Loading branch information
Showing
4 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/react-server-test-pages/pages/navigation/navigateTo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {navigateTo} from "react-server"; | ||
|
||
const go = page => navigateTo( | ||
`/navigation/navigateTo?cur=${page}`, | ||
{reuseDom: true} | ||
) | ||
|
||
const Nav = ({cur}) => <div onClick={() => go(cur+1)}> | ||
<div>Current page: {cur}</div> | ||
<div>Click for next page</div> | ||
</div> | ||
|
||
export default class NavigateToPage { | ||
getElements() { | ||
return <Nav cur={+this.getRequest().getQuery().cur||0} /> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import ClientRequest from "../ClientRequest"; | ||
import History from "../components/History"; | ||
import {getCurrentRequestContext} from "../context/RequestContext"; | ||
|
||
// This initiates a client transition to `path` with `options`. | ||
// Just a convenience wrapper. | ||
export default function navigateTo(path, options) { | ||
getCurrentRequestContext().navigate( | ||
new ClientRequest(path, options), | ||
History.events.PUSHSTATE | ||
); | ||
} |