@tramvai/module-router 1.48.3 → 1.50.1

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/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # @tramvai/module-router
2
2
 
3
- Module for routing in the application.
4
- Exports two sub-modules: with client SPA transitions, and no-SPA.
3
+ Module for routing in the application. Exports two sub-modules: with client SPA transitions, and no-SPA.
5
4
 
6
5
  ## Installation
7
6
 
@@ -28,21 +27,28 @@ createApp({
28
27
 
29
28
  The module is based on the library [@tinkoff/router](references/libs/router.md)
30
29
 
30
+ ### Default Settings
31
+
32
+ Next [settings](references/libs/router.md#constructor-options) are used
33
+
34
+ - `trailingSlashes = true`
35
+ - `mergeSlashes = true`
36
+
31
37
  ### Navigation flow on the server
32
38
 
33
- ![Diagramm](/img/router/navigate-flow-server.drawio.svg)
39
+ ![Diagram](/img/router/navigate-flow-server.drawio.svg)
34
40
 
35
41
  ### Flow of the first navigation on the client
36
42
 
37
- ![Diagramm](/img/router/rehydrate-client.drawio.svg)
43
+ ![Diagram](/img/router/rehydrate-client.drawio.svg)
38
44
 
39
45
  ### Flow of navigation on the client without SPA transitions
40
46
 
41
- ![Diagramm](/img/router/navigate-flow-client-no-spa.drawio.svg)
47
+ ![Diagram](/img/router/navigate-flow-client-no-spa.drawio.svg)
42
48
 
43
49
  ### Flow of navigation on the client with SPA transitions
44
50
 
45
- ![Diagramm](/img/router/navigate-flow-client-spa.drawio.svg)
51
+ ![Diagram](/img/router/navigate-flow-client-spa.drawio.svg)
46
52
 
47
53
  ## API
48
54
 
@@ -275,8 +281,7 @@ You can work with routing inside React components using hooks and components - `
275
281
 
276
282
  ### How to set static routes
277
283
 
278
- [RouterModule](references/modules/router.md) allows you to add new routes when configuring your application.
279
- The second way is to pass static routes to DI via the `ROUTES_TOKEN` token.
284
+ [RouterModule](references/modules/router.md) allows you to add new routes when configuring your application. The second way is to pass static routes to DI via the `ROUTES_TOKEN` token.
280
285
 
281
286
  <p>
282
287
  <details>
@@ -289,7 +294,7 @@ The second way is to pass static routes to DI via the `ROUTES_TOKEN` token.
289
294
 
290
295
  ### How to set Route Guard
291
296
 
292
- [ROUTER_GUARD_TOKEN](references/modules/router.md#router_guard_token) is set as an asynchronous function, which allows you to perform various actions and influence the routing behavior.
297
+ `ROUTER_GUARD_TOKEN` is set as an asynchronous function, which allows you to perform various actions and influence the routing behavior.
293
298
 
294
299
  <p>
295
300
  <details>
@@ -300,6 +305,14 @@ The second way is to pass static routes to DI via the `ROUTES_TOKEN` token.
300
305
  </details>
301
306
  </p>
302
307
 
308
+ ### How to add transition hooks
309
+
310
+ [Transition hooks](references/libs/router.md#transition-hooks) allows to subscribe on different steps of the transition
311
+
312
+ 1. Get router instance with `ROUTER_TOKEN` token
313
+ 2. Use methods `registerHook`, `registerSyncHook` to add new hooks to the router
314
+ 3. Registration should happen as soon as possible so appropriate line is `customerStart` as it executes before navigation happens.
315
+
303
316
  ### How to set the Not found route
304
317
 
305
318
  The Not found route is used if the corresponding route is not found for the url.
@@ -317,8 +330,7 @@ Such a route is specified in the list of routes with the special `*` character i
317
330
 
318
331
  ### How to change Not found route response status
319
332
 
320
- By default, responses for the Not found route return a status of 200.
321
- You can change status in custom Route Guard, by using `RESPONSE_MANAGER_TOKEN`.
333
+ By default, responses for the Not found route return a status of 200. You can change status in custom Route Guard, by using `RESPONSE_MANAGER_TOKEN`.
322
334
 
323
335
  <p>
324
336
  <details>
@@ -333,9 +345,7 @@ You can change status in custom Route Guard, by using `RESPONSE_MANAGER_TOKEN`.
333
345
 
334
346
  For example, you make a important request in action, and if this request will fail, application need to return 500 or 404 status.
335
347
 
336
- Page actions running after router navigation flow, when route is completely resolved.
337
- You can change status by using `RESPONSE_MANAGER_TOKEN`.
338
- If you want to prevent page component rendering, you can throw `NotFoundError` from `@tinkoff/errors` library.
348
+ Page actions running after router navigation flow, when route is completely resolved. You can change status by using `RESPONSE_MANAGER_TOKEN`. If you want to prevent page component rendering, you can throw `NotFoundError` from `@tinkoff/errors` library.
339
349
 
340
350
  <p>
341
351
  <details>
@@ -258,6 +258,13 @@ class PageService {
258
258
  const group = this.getComponentsGroupName();
259
259
  return this.componentRegistry.get(name, group);
260
260
  }
261
+ resolveComponentFromConfig(property) {
262
+ var _a;
263
+ const configName = `${property}Component`;
264
+ const defaultComponent = `${property}Default`;
265
+ const componentName = (_a = this.getConfig()[configName]) !== null && _a !== void 0 ? _a : defaultComponent;
266
+ return this.getComponent(componentName) || this.getComponent(defaultComponent);
267
+ }
261
268
  getComponentsGroupName() {
262
269
  const { bundle, pageComponent } = this.getConfig();
263
270
  const group = isFileSystemPageComponent(pageComponent) ? pageComponent : bundle;
package/lib/index.es.js CHANGED
@@ -260,6 +260,13 @@ class PageService {
260
260
  const group = this.getComponentsGroupName();
261
261
  return this.componentRegistry.get(name, group);
262
262
  }
263
+ resolveComponentFromConfig(property) {
264
+ var _a;
265
+ const configName = `${property}Component`;
266
+ const defaultComponent = `${property}Default`;
267
+ const componentName = (_a = this.getConfig()[configName]) !== null && _a !== void 0 ? _a : defaultComponent;
268
+ return this.getComponent(componentName) || this.getComponent(defaultComponent);
269
+ }
263
270
  getComponentsGroupName() {
264
271
  const { bundle, pageComponent } = this.getConfig();
265
272
  const group = isFileSystemPageComponent(pageComponent) ? pageComponent : bundle;
package/lib/index.js CHANGED
@@ -272,6 +272,13 @@ class PageService {
272
272
  const group = this.getComponentsGroupName();
273
273
  return this.componentRegistry.get(name, group);
274
274
  }
275
+ resolveComponentFromConfig(property) {
276
+ var _a;
277
+ const configName = `${property}Component`;
278
+ const defaultComponent = `${property}Default`;
279
+ const componentName = (_a = this.getConfig()[configName]) !== null && _a !== void 0 ? _a : defaultComponent;
280
+ return this.getComponent(componentName) || this.getComponent(defaultComponent);
281
+ }
275
282
  getComponentsGroupName() {
276
283
  const { bundle, pageComponent } = this.getConfig();
277
284
  const group = experiments.isFileSystemPageComponent(pageComponent) ? pageComponent : bundle;
@@ -21,6 +21,7 @@ export declare class PageService implements PageServiceInterface {
21
21
  go(to: number, options?: HistoryOptions): Promise<void>;
22
22
  addComponent(name: string, component: any): void;
23
23
  getComponent(name: string): any;
24
+ resolveComponentFromConfig(property: 'page' | 'layout' | 'header' | 'footer'): any;
24
25
  private getComponentsGroupName;
25
26
  }
26
27
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-router",
3
- "version": "1.48.3",
3
+ "version": "1.50.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "browser": {
@@ -23,24 +23,24 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@tinkoff/errors": "0.2.18",
26
- "@tinkoff/router": "0.1.65",
26
+ "@tinkoff/router": "0.1.66",
27
27
  "@tinkoff/url": "0.7.37",
28
- "@tramvai/tokens-render": "1.48.3",
29
- "@tramvai/tokens-router": "1.48.3",
30
- "@tramvai/tokens-server": "1.48.3",
31
- "@tramvai/experiments": "1.48.3"
28
+ "@tramvai/tokens-render": "1.50.1",
29
+ "@tramvai/tokens-router": "1.50.1",
30
+ "@tramvai/tokens-server": "1.50.1",
31
+ "@tramvai/experiments": "1.50.1"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@tinkoff/utils": "^2.1.2",
35
- "@tramvai/cli": "1.48.3",
36
- "@tramvai/core": "1.48.3",
37
- "@tramvai/module-log": "1.48.3",
38
- "@tramvai/module-server": "1.48.3",
39
- "@tramvai/papi": "1.48.3",
40
- "@tramvai/state": "1.48.3",
41
- "@tramvai/test-helpers": "1.48.3",
42
- "@tramvai/test-mocks": "1.48.3",
43
- "@tramvai/tokens-common": "1.48.3",
35
+ "@tramvai/cli": "1.50.1",
36
+ "@tramvai/core": "1.50.1",
37
+ "@tramvai/module-log": "1.50.1",
38
+ "@tramvai/module-server": "1.50.1",
39
+ "@tramvai/papi": "1.50.1",
40
+ "@tramvai/state": "1.50.1",
41
+ "@tramvai/test-helpers": "1.50.1",
42
+ "@tramvai/test-mocks": "1.50.1",
43
+ "@tramvai/tokens-common": "1.50.1",
44
44
  "@tinkoff/dippy": "0.7.36",
45
45
  "react": "*",
46
46
  "tslib": "^2.0.3"