Skip to content

Commit

Permalink
feat(RouteNavigate): nav(-1) goBack history support (#6324)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickJS committed May 16, 2024
1 parent 3b862ef commit d79b934
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/docs/src/routes/api/qwik-city/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@
}
],
"kind": "TypeAlias",
"content": "```typescript\nexport type RouteNavigate = QRL<(path?: string, options?: {\n type?: Exclude<NavigationType, 'initial'>;\n forceReload?: boolean;\n replaceState?: boolean;\n scroll?: boolean;\n} | boolean) => Promise<void>>;\n```\n**References:** [NavigationType](#navigationtype)",
"content": "```typescript\nexport type RouteNavigate = QRL<(path?: string | number, options?: {\n type?: Exclude<NavigationType, 'initial'>;\n forceReload?: boolean;\n replaceState?: boolean;\n scroll?: boolean;\n} | boolean) => Promise<void>>;\n```\n**References:** [NavigationType](#navigationtype)",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/runtime/src/types.ts",
"mdFile": "qwik-city.routenavigate.md"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/routes/api/qwik-city/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ URL
```typescript
export type RouteNavigate = QRL<
(
path?: string,
path?: string | number,
options?:
| {
type?: Exclude<NavigationType, "initial">;
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-city/runtime/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export interface RouteLocation {
}

// @public (undocumented)
export type RouteNavigate = QRL<(path?: string, options?: {
export type RouteNavigate = QRL<(path?: string | number, options?: {
type?: Exclude<NavigationType, 'initial'>;
forceReload?: boolean;
replaceState?: boolean;
Expand Down
6 changes: 6 additions & 0 deletions packages/qwik-city/runtime/src/qwik-city-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ export const QwikCityProvider = component$<QwikCityProps>((props) => {
replaceState = false,
scroll = true,
} = typeof opt === 'object' ? opt : { forceReload: opt };
if (typeof path === 'number') {
if (isBrowser) {
history.go(path);
}
return;
}
const lastDest = routeInternal.value.dest;
const dest = path === undefined ? lastDest : toUrl(path, routeLocation.url);

Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-city/runtime/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export type ScrollState = {
/** @public */
export type RouteNavigate = QRL<
(
path?: string,
path?: string | number,
options?:
| {
type?: Exclude<NavigationType, 'initial'>;
Expand Down

0 comments on commit d79b934

Please sign in to comment.