Gathering detailed insights and metrics for @superwf/mobx-react-router
Gathering detailed insights and metrics for @superwf/mobx-react-router
Gathering detailed insights and metrics for @superwf/mobx-react-router
Gathering detailed insights and metrics for @superwf/mobx-react-router
npm install @superwf/mobx-react-router
Typescript
Module System
Node Version
NPM Version
71.9
Supply Chain
98.9
Quality
75.5
Maintenance
100
Vulnerability
100
License
TypeScript (81.48%)
JavaScript (18.52%)
Total Downloads
325,357
Last Day
65
Last Week
646
Last Month
4,422
Last Year
65,839
13 Stars
63 Commits
9 Forks
1 Watching
14 Branches
1 Contributors
Latest Version
7.4.0
Package Id
@superwf/mobx-react-router@7.4.0
Unpacked Size
185.24 kB
Size
25.11 kB
File Count
12
NPM Version
8.1.0
Node Version
16.13.0
Cumulative downloads
Total Downloads
Last day
-74.5%
65
Compared to previous day
Last week
-27.1%
646
Compared to previous week
Last month
-29.2%
4,422
Compared to previous month
Last year
-39.4%
65,839
Compared to previous year
3
45
Keep your MobX state in sync with react-router via a RouterStore
.
Router location state is observable, so any references to it in MobX
components will cause the component to re-render when the location changes.
This repo is forked from alisd23/mobx-react-router.
Totally rewrite with typescript and has type definition together.
Tested 🥳
💡 Note 2021-8-16 update to v7 for compatible with history v5, mobx v6, react-router v5 and path-to-regexp v6
Since History
upgrade to V5, its api changed a lot.
So please READ API part again even you have used mobx-react-router.
💡 Note if you need to work woth old version react-router and history, install v6 by npm install --save @superwf/mobx-react-router@6.0.0
1npm install --save @superwf/mobx-react-router
Complete code here: example
router.js
1import { createBrowserHistory } from 'history' 2import { RouterStore } from '@superwf/mobx-react-router' 3 4const browserHistory = createBrowserHistory() 5export const router = new RouterStore(browserHistory)
index.js
1import React from 'react' 2import ReactDOM from 'react-dom' 3import { Router } from 'react-router' 4import App from './App' 5import { router } from './router' 6 7ReactDOM.render( 8 <Router history={router.history}> 9 <App /> 10 </Router> 11 document.getElementById('root') 12)
App.js
1import React, { Component } from 'react' 2import { observer } from 'mobx-react-lite' 3import { router } from './router' 4 5export const App = observer(() => { 6 const { location, push, back } = router 7 return ( 8 <div> 9 <span>Current pathname: {location.pathname}</span> 10 <button onClick={() => push('/test')}>go to "/test"</button> 11 <button onClick={back}>Go Back</button> 12 </div> 13 ) 14})
window.MobxReactRouter
<script type="javascript" src="https://unpkg.com/@superwf/mobx-react-router@latest/dist/mobx-react-router.min.js"></script>
1import { RouterStore } from 'https://unpkg.com/@superwf/mobx-react-router/module/index.js'
param: history
- A variant of a history object, usually browserHistory
1const browserHistory = createBrowserHistory() 2// or hashHistory or memoryHistory 3const router = new RouterStore(browserHistory)
A RouterStore instance has the following properties:
state
(observable) - sync with history state, type as below.1{ action: history.action, location: history.location }
1router.push('/test1') 2router.location.pathname // '/test1'
history the history instance from constructor. Use it as your will, do not update it.
pathList string[], observable, used to match pathValue
. Do not use it directly unless you absolutely know your purpose.
query url search object format.
1router.push('/abc?a=1&b=2') 2router.query // { a: '1', b: '2' } 3router.push('/abc?id=1&id=2') 4router.query // { id: ['1', '2'] }
#
.1router.push('/abc#xxx') 2router.hashValue // 'xxx'
pathList
work together.1router.appendPathList('/user/:name') 2router.push('/user/xxx') 3router.hashValue // 'xxx'
1router.push('/test1') 2router.location.pathname // '/test1' 3router.stopSyncWithHistory() 4router.push('/test2') // not sync any more 5router.location.pathname // '/test1'
Subscribes to any changes in the store's location
observable,
and run the listener at once with current history state.
Returns an unsubscribe function which destroys the listener
1const stopListen = router.subscribe(({ location }) => console.log(location.pathname)) 2router.push('/test1') // output '/test1' 3stopListen() 4router.push('/test2') // no output any more
Append or prepend new paths to pathList
property,
💡 Note path in pathList order is important, first matched path will return the pathValue
result.
Use prependPathList
for some path
which has high priority.
1router.appendPathList('/user/:name') 2router.push('/user/rock') // match "/user/:name" 3router.pathValue // now get a path param: { name: 'rock' }
The following methods bind to the history instance, for more detail read here: history methods:
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
24 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More