由 History 实现实现的接口,可以作为 Router.history 传递给路由器
Properties
base
• Readonly
base: string
附加到每个 url 的基本路径。 这允许通过将 base
设置为 /sub-folder
来在 example.com/sub-folder
等域的子文件夹中托管 SPA
location
• Readonly
location: string
当前历史位置
state
• Readonly
state: HistoryState
当前历史状态
Methods
createHref
▸ createHref(location
): string
生成要在锚标记中使用的相应 href。
Parameters
名称 | 类型 | 说明 |
---|---|---|
location | string | 应该创建 href 的历史位置 |
Returns
string
destroy
▸ destroy(): void
清除历史实现附加的任何事件侦听器。
Returns
void
go
▸ go(delta
, triggerListeners?
): void
沿给定方向遍历历史。
Example
myHistory.go(-1) // equivalent to window.history.back()
myHistory.go(1) // equivalent to window.history.forward()
Parameters
名称 | 类型 | 说明 |
---|---|---|
delta | number | 旅行的距离。 如果 delta < 0,它将返回,如果它是 > 0,它将前进该条目数。 |
triggerListeners? | boolean | 这是否应该触发附加到历史的听众 |
Returns
void
listen
▸ listen(callback
): () => void
将侦听器附加到从外部触发导航(如浏览器后退和前进按钮)或将true
传递给 RouterHistory.back
和 RouterHistory.forward
时触发的 History 实现
Parameters
名称 | 类型 | 说明 |
---|---|---|
callback | NavigationCallback | 要附加的侦听器 |
Returns
fn
移除侦听器的回调
▸ (): void
将侦听器附加到从外部触发导航(如浏览器后退和前进按钮)或将true
传递给RouterHistory.back
和RouterHistory.forward
时触发的历史实现
Returns
void
移除侦听器的回调
push
▸ push(to
, data?
): void
导航到一个位置。 在 HTML5 History 实现的情况下,这将调用history.pushState
来有效地更改 URL。
Parameters
名称 | 类型 | 说明 |
---|---|---|
to | string | 要推送的位置 |
data? | HistoryState | 与导航条目关联的可选 HistoryState |
Returns
void
replace
▸ replace(to
, data?
): void
与 push 相同,但执行的是 history.replaceState
而不是 history.pushState
Parameters
名称 | 类型 | 说明 |
---|---|---|
to | string | location to set |
data? | HistoryState | 与导航条目关联的可选 HistoryState |
Returns
void