Socket
Socket
Sign inDemoInstall

@sanity/state-router

Package Overview
Dependencies
1
Maintainers
6
Versions
702
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0-beta.3 to 0.2.0

LICENSE

45

package.json
{
"name": "@sanity/state-router",
"version": "0.2.0-beta.3",
"version": "0.2.0",
"description": "A path pattern => state object bidirectional mapper",

@@ -23,35 +23,34 @@ "main": "lib/index.js",

"dependencies": {
"lodash": "^4.15.0"
"lodash": "^4.17.2"
},
"devDependencies": {
"babel-cli": "^6.14.0",
"babel-core": "^6.14.0",
"babel-eslint": "^7.0.0",
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
"babel-eslint": "^7.1.0",
"babel-plugin-lodash": "^3.2.9",
"babel-plugin-syntax-class-properties": "^6.13.0",
"babel-plugin-syntax-flow": "^6.13.0",
"babel-plugin-syntax-flow": "^6.18.0",
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
"babel-plugin-transform-class-properties": "^6.16.0",
"babel-plugin-transform-flow-strip-types": "^6.14.0",
"babel-plugin-transform-object-rest-spread": "^6.8.0",
"babel-polyfill": "^6.13.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
"babel-register": "^6.14.0",
"babel-plugin-transform-class-properties": "^6.19.0",
"babel-plugin-transform-flow-strip-types": "^6.18.0",
"babel-plugin-transform-object-rest-spread": "^6.19.0",
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-register": "^6.18.0",
"babelify": "^7.3.0",
"browserify": "^13.1.0",
"browserify": "^13.1.1",
"error-capture-middleware": "0.0.2",
"eslint": "^3.4.0",
"eslint": "^3.10.2",
"eslint-config-bengler": "^2.0.0",
"eslint-plugin-flowtype-errors": "^1.4.1",
"eslint-plugin-import": "^2.0.1",
"eslint-plugin-react": "^6.2.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-react": "^6.7.1",
"express": "^4.14.0",
"flow-bin": "^0.33.0",
"history": "^4.3.0",
"flow-bin": "^0.35.0",
"history": "^4.4.0",
"in-publish": "^2.0.0",
"object-inspect": "^1.2.1",
"quickreload": "^2.1.2",
"react": "^15.3.1",
"react-dom": "^15.3.1",
"react": "^15.4.0",
"react-dom": "^15.4.0",
"rebundler": "^0.3.0",

@@ -61,3 +60,3 @@ "remon": "^1.0.2",

"staticr": "^4.0.2",
"tap": "^7.0.0"
"tap": "^8.0.0"
},

@@ -64,0 +63,0 @@ "repository": {

@@ -12,3 +12,3 @@ ## @sanity/state-router

```js
import {route} from 'xroute'
import {route} from '@sanity/state-router'

@@ -62,3 +62,3 @@ const router = route('/', [

```
- `Options`:
- `Options`:
```

@@ -91,6 +91,58 @@ {

Now, `/about` would resolve to the state `{page: 'about'}` which unambiguously can map back to `/page`, and an empty state can map to `/`. To figure out if you are on the index page, you can check for `state.page == null`, (and set the state.page to null to navigate back to the index)
### No query params
Query parameters doesn't work too well with router scopes as they operate in a global namespace. A possible workaround is to "fake" query params in a path segment using transforms:
```js
function decodeParams(pathsegment) {
return pathsegment.split(';')
.reduce((params, pair) => {
const [key, value] = pair.split('=')
params[key] = value
return params
}, {})
}
function encodeParams(params) {
return Object.keys(params)
.map(key => `${key}=${params[key]}`)
.join(';')
}
Now, `/about` would resolve to the state `{page: 'about'}` which unambiguously can map back to `/page`, and an empty state can map to `/`. To figure out if you are on the index page, you can check for `state.page == null`, (and set the state.page to null to navigate back to the index)
const router = route('/some/:section/:settings', {
transform: {
settings: {
toState: decodeParams,
toPath: encodeParams
}
}
}, route('/other/:page'))
```
This call...
```js
router.decode('/some/bar/width=full;view=details')
```
...will return the following state
```js
{
section: 'bar',
settings: {
width: 'full',
view: 'details',
}
}
```
Conversely calling
```js
router.encode({
section: 'bar',
settings: {
width: 'full',
view: 'details',
}
})
```
will return
```
/some/bar/width=full;view=details
```

@@ -149,4 +201,4 @@ ## Scopes

const router = route('/some/basepath', [
route('/:foo'),
route('/:bar')
route('/:foo'),
route('/:bar')
])

@@ -167,3 +219,3 @@ ```

```
```js
const redirectTo = router.getRedirectBase(location.pathname)

@@ -173,2 +225,6 @@ if (redirectTo) {

}
```
```
## License
MIT-licensed

@@ -54,2 +54,1 @@ // @flow

}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc