@tinkoff/router 0.1.68 → 0.1.69

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.
Files changed (2) hide show
  1. package/README.md +14 -3
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -60,8 +60,12 @@ export const myGuard: NavigationGuard = async ({ to }) => {
60
60
  return false; // block this transition
61
61
  }
62
62
 
63
- if (to.config.redirect) {
64
- return '/login/'; // call a redirect to the specified page
63
+ if (typeof to.config.redirect === 'string') {
64
+ return to.config.redirect; // call a redirect to the specified page
65
+ }
66
+
67
+ if (typeof to.config.needAuth && !isAuth()) {
68
+ return { url: '/login/', code: '302' }; // redirect to page with NavigateOptions
65
69
  }
66
70
 
67
71
  // if nothing is returned, the transition will be performed as usual
@@ -83,7 +87,7 @@ The behaviour of routing depends on the result of executing guards functions and
83
87
  - if all of the guards returns `undefined` than navigation will continue executing
84
88
  - if any of the guards returns `false` than navigation is getting blocked and next action differs on server and client
85
89
  - if any of the guards returns `string` it is considered as url to which redirect should be happen
86
- - if any of the guards returns `NavigateOptions` interface, `url` property from it is considered as url to which redirect should be happen
90
+ - if any of the guards returns [`NavigateOptions`](#navigateoptions) interface, `url` property from it is considered as url to which redirect should be happen
87
91
 
88
92
  ### Transitions hooks
89
93
 
@@ -172,6 +176,13 @@ router.updateCurrentRoute({ query: { a: '1' } });
172
176
  2. `change`
173
177
  3. `afterUpdateCurrent`
174
178
 
179
+ ### NavigateOptions
180
+
181
+ Object that allows to specify transition options both to [navigate](#navigate) and [updateCurrentRoute](#updatecurrentroute) transitions
182
+
183
+ - `code` - redirect code that is returned on server in case of redirects
184
+ - `navigateState` - any additional data that is stored with route
185
+
175
186
  ### Working with query
176
187
 
177
188
  #### query option
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkoff/router",
3
- "version": "0.1.68",
3
+ "version": "0.1.69",
4
4
  "description": "router",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",