@akanjs/client 0.9.3 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/src/router.js CHANGED
@@ -74,51 +74,55 @@ class Router {
74
74
  #initNextClientRouter(options) {
75
75
  this.#instance = {
76
76
  push: (href) => {
77
+ const router2 = options.router;
77
78
  const { path, pathname } = this.#getPathInfo(href);
78
79
  this.#postPathChange({ path, pathname });
79
- options.router.push(pathname);
80
+ void router2.push(pathname);
80
81
  },
81
82
  replace: (href) => {
83
+ const router2 = options.router;
82
84
  const { path, pathname } = this.#getPathInfo(href);
83
85
  this.#postPathChange({ path, pathname });
84
- options.router.replace(pathname);
86
+ void router2.replace(pathname);
85
87
  },
86
88
  back: () => {
89
+ const router2 = options.router;
87
90
  const { path, pathname } = this.#getPathInfo(document.referrer);
88
91
  this.#postPathChange({ path, pathname });
89
- options.router.back();
92
+ router2.back();
90
93
  },
91
94
  refresh: () => {
95
+ const router2 = options.router;
92
96
  const { path, pathname } = this.#getPathInfo(location.pathname);
93
97
  this.#postPathChange({ path, pathname });
94
- options.router.refresh();
98
+ router2.reload();
95
99
  }
96
100
  };
97
101
  }
98
102
  #initCSRClientRouter(options) {
99
103
  this.#instance = {
100
- push: (href) => {
104
+ push: (href, routeOptions) => {
101
105
  const { path, pathname } = this.#getPathInfo(href);
102
106
  if (location.pathname === pathname)
103
107
  return;
104
108
  this.#postPathChange({ path, pathname });
105
- options.router.push(pathname);
109
+ options.router.push(pathname, routeOptions);
106
110
  },
107
- replace: (href) => {
111
+ replace: (href, routeOptions) => {
108
112
  const { path, pathname } = this.#getPathInfo(href);
109
113
  if (location.pathname === pathname)
110
114
  return;
111
115
  this.#postPathChange({ path, pathname });
112
116
  setTimeout(() => {
113
- options.router.replace(pathname);
117
+ options.router.replace(pathname, routeOptions);
114
118
  }, 0);
115
119
  },
116
- back: () => {
120
+ back: (routeOptions) => {
117
121
  const { path, pathname } = this.#getPathInfo(document.referrer);
118
122
  if (location.pathname === pathname)
119
123
  return;
120
124
  this.#postPathChange({ path, pathname });
121
- options.router.back();
125
+ options.router.back(routeOptions);
122
126
  },
123
127
  refresh: () => {
124
128
  const { path, pathname } = this.#getPathInfo(location.pathname);
@@ -138,21 +142,21 @@ class Router {
138
142
  import_common.Logger.log(`pathChange-start:${path}`);
139
143
  window.parent.postMessage({ type: "pathChange", path, pathname }, "*");
140
144
  }
141
- push(href) {
145
+ push(href, routeOptions) {
142
146
  this.#checkInitialized();
143
- this.#instance.push(href);
147
+ this.#instance.push(href, routeOptions);
144
148
  return void 0;
145
149
  }
146
- replace(href) {
150
+ replace(href, routeOptions) {
147
151
  this.#checkInitialized();
148
- this.#instance.replace(href);
152
+ this.#instance.replace(href, routeOptions);
149
153
  return void 0;
150
154
  }
151
- back() {
155
+ back(routeOptions) {
152
156
  if (import_base.baseClientEnv.side === "server")
153
157
  throw new Error("back is only available in client side");
154
158
  this.#checkInitialized();
155
- this.#instance.back();
159
+ this.#instance.back(routeOptions);
156
160
  return void 0;
157
161
  }
158
162
  refresh() {
package/esm/src/router.js CHANGED
@@ -51,51 +51,55 @@ class Router {
51
51
  #initNextClientRouter(options) {
52
52
  this.#instance = {
53
53
  push: (href) => {
54
+ const router2 = options.router;
54
55
  const { path, pathname } = this.#getPathInfo(href);
55
56
  this.#postPathChange({ path, pathname });
56
- options.router.push(pathname);
57
+ void router2.push(pathname);
57
58
  },
58
59
  replace: (href) => {
60
+ const router2 = options.router;
59
61
  const { path, pathname } = this.#getPathInfo(href);
60
62
  this.#postPathChange({ path, pathname });
61
- options.router.replace(pathname);
63
+ void router2.replace(pathname);
62
64
  },
63
65
  back: () => {
66
+ const router2 = options.router;
64
67
  const { path, pathname } = this.#getPathInfo(document.referrer);
65
68
  this.#postPathChange({ path, pathname });
66
- options.router.back();
69
+ router2.back();
67
70
  },
68
71
  refresh: () => {
72
+ const router2 = options.router;
69
73
  const { path, pathname } = this.#getPathInfo(location.pathname);
70
74
  this.#postPathChange({ path, pathname });
71
- options.router.refresh();
75
+ router2.reload();
72
76
  }
73
77
  };
74
78
  }
75
79
  #initCSRClientRouter(options) {
76
80
  this.#instance = {
77
- push: (href) => {
81
+ push: (href, routeOptions) => {
78
82
  const { path, pathname } = this.#getPathInfo(href);
79
83
  if (location.pathname === pathname)
80
84
  return;
81
85
  this.#postPathChange({ path, pathname });
82
- options.router.push(pathname);
86
+ options.router.push(pathname, routeOptions);
83
87
  },
84
- replace: (href) => {
88
+ replace: (href, routeOptions) => {
85
89
  const { path, pathname } = this.#getPathInfo(href);
86
90
  if (location.pathname === pathname)
87
91
  return;
88
92
  this.#postPathChange({ path, pathname });
89
93
  setTimeout(() => {
90
- options.router.replace(pathname);
94
+ options.router.replace(pathname, routeOptions);
91
95
  }, 0);
92
96
  },
93
- back: () => {
97
+ back: (routeOptions) => {
94
98
  const { path, pathname } = this.#getPathInfo(document.referrer);
95
99
  if (location.pathname === pathname)
96
100
  return;
97
101
  this.#postPathChange({ path, pathname });
98
- options.router.back();
102
+ options.router.back(routeOptions);
99
103
  },
100
104
  refresh: () => {
101
105
  const { path, pathname } = this.#getPathInfo(location.pathname);
@@ -115,21 +119,21 @@ class Router {
115
119
  Logger.log(`pathChange-start:${path}`);
116
120
  window.parent.postMessage({ type: "pathChange", path, pathname }, "*");
117
121
  }
118
- push(href) {
122
+ push(href, routeOptions) {
119
123
  this.#checkInitialized();
120
- this.#instance.push(href);
124
+ this.#instance.push(href, routeOptions);
121
125
  return void 0;
122
126
  }
123
- replace(href) {
127
+ replace(href, routeOptions) {
124
128
  this.#checkInitialized();
125
- this.#instance.replace(href);
129
+ this.#instance.replace(href, routeOptions);
126
130
  return void 0;
127
131
  }
128
- back() {
132
+ back(routeOptions) {
129
133
  if (baseClientEnv.side === "server")
130
134
  throw new Error("back is only available in client side");
131
135
  this.#checkInitialized();
132
- this.#instance.back();
136
+ this.#instance.back(routeOptions);
133
137
  return void 0;
134
138
  }
135
139
  refresh() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/client",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/router.d.ts CHANGED
@@ -1,7 +1,10 @@
1
+ export interface RouteOptions {
2
+ scrollToTop?: boolean;
3
+ }
1
4
  export interface RouterInstance {
2
- push: (href: string) => void;
3
- replace: (href: string) => void;
4
- back: () => void;
5
+ push: (href: string, routeOptions?: RouteOptions) => void;
6
+ replace: (href: string, routeOptions?: RouteOptions) => void;
7
+ back: (routeOptions?: RouteOptions) => void;
5
8
  refresh: () => void;
6
9
  }
7
10
  interface RouterOptions {
@@ -29,9 +32,9 @@ declare class Router {
29
32
  #private;
30
33
  isInitialized: boolean;
31
34
  init(options: NextClientRouterOption | NextServerRouterOption | CSRClientRouterOption): void;
32
- push(href: string): never;
33
- replace(href: string): never;
34
- back(): never;
35
+ push(href: string, routeOptions?: RouteOptions): never;
36
+ replace(href: string, routeOptions?: RouteOptions): never;
37
+ back(routeOptions?: RouteOptions): never;
35
38
  refresh(): never;
36
39
  redirect(href: string): Promise<never>;
37
40
  notFound(): never;