https://github.com/aleclarson/journey
Client-side routing
https://github.com/aleclarson/journey
Last synced: 10 months ago
JSON representation
Client-side routing
- Host: GitHub
- URL: https://github.com/aleclarson/journey
- Owner: aleclarson
- Created: 2018-01-27T16:51:00.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-05T16:55:14.000Z (over 7 years ago)
- Last Synced: 2025-03-11T12:33:48.614Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# journey v2.0.0
Browser navigation enhanced.
- Timestamps
- Hard-reload detection
- Useful events: `back`, `forward`, `push`, `set`
### observe(function)
Get notified about navigation events.
- `back` the user went back 1+ times in history using native controls
- `forward` the user went forward 1+ times in history using native controls
- `push` your code called the `push` method
- `set` your code called the `set` method
You must call `observe` only once. Within the observer, you can choose to
emit to many listeners or do everything you need from a single module.
The observer is called asynchronously, and is passed the `state` object.
### push(path: string, state: ?object)
Visit the given path.
Under the hood, this calls the `history.pushState` method.
The `path` argument must begin with `/` if you want to change the entire path.
Otherwise, you will visit a path relative to the current path. This works for
`#hash`, `?query`, and `subpath` strings. For example, if the current path is
`/foo`, the previous strings navigate to `/foo#hash`, `/foo?query`, and `/foo/subpath`.
### set(path: string, state: ?object)
Change the path by overwriting the current point in history.
The optional `state` will override the current state entirely.
Under the hood, this calls the `history.replaceState` method.
### back()
Shortcut to `history.back`
### forward()
Shortcut to `history.forward`
### get()
Returns the cached result of `location.pathname + location.hash + location.search`
### is(string)
Shorthand for `journey.get() === "/path/"`
### emit(id: string)
### chain: object[]
The array of "path states" visited in the current session.
### index: number
The current position in the `chain` array.
### state: object
The current "path state", which is guaranteed to have the following properties:
- `session: number` when the current session began
- `time: number` when this path state was created
- `title: string` the value of `document.title`
You can store anything JSON-compatible in this object, but you should use the
`push` or `set` methods to do that. If you want to replace the entire state
without changing the path, setting this property is the easiest way.
### title: string
Shortcut to `document.title`
You should set this property instead of setting `document.title` directly
so the history can be properly updated.
### origin: string
The first path in the current session.