Gathering detailed insights and metrics for react-router-concent
Gathering detailed insights and metrics for react-router-concent
Gathering detailed insights and metrics for react-router-concent
Gathering detailed insights and metrics for react-router-concent
npm install react-router-concent
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
4 Stars
48 Commits
1 Forks
2 Watchers
1 Branches
1 Contributors
Updated on Apr 08, 2022
Latest Version
2.3.0
Package Id
react-router-concent@2.3.0
Unpacked Size
50.77 kB
Size
11.23 kB
File Count
30
NPM Version
6.14.13
Node Version
14.17.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
51
连接concent
与react-router
,让你的concent
应用完美接入react-router
.
在app顶层实例一个ConnectRouter,让concent
连接上react-router
1// 设置callUrlChangeOnInit为true时, 2// 由路由切换导致的挂载上的组件,如果该组件定义了$onUrlChanged,则初次挂载的时候就会触发器$onUrlChanged函数的执行 3<ConnectRouter callUrlChangeOnInit={true} /> 4 5// callUrlChangeOnInit默认是false, 6// 此种情况,定义了$onUrlChanged的cc类在初次挂载的时候,不会触发$onUrlChanged函数的执行 7// 只有在存在期间,如果用户反复点同一个路由url,会触发$onUrlChanged函数的执行 8<ConnectRouter />
1createHistoryProxy: (history: RouterHistory, callUrlChangeOnInit?:boolean)
在顶层容器里,只会初始化一次的地方掉用createHistoryProxy
负责跳转匹配路径规则的路由
to
1import { Link } from 'react-router-concent'; 2 3<Link to="/user/:id" style={{border:1px}}>
除了Link
,用户也可以使用history直接跳转或者执行其他操作,api与react-router
提供的完全保持一致
react-router
的提供与实现1import { history } from 'react-router-concent'; 2 3<div onClick={()=>history.push('/path')}>点我跳转</div>
$$onUrlChanged
在cc类setup
里设定事件onUrlChanged
的监听函数,当调用了history.push
、history.goBack
,history.goForward
、history.replace
的时候, 如果对应的组件还处于存在期,concent
会触发该函数
1@register() 2class Foo extends React.Component{ 3 $$setup(ctx){ 4 ctx.on('onUrlChanged', ()=>{ 5 // do something here like initPage 6 }); 7 } 8} 9 10<Route path="/user/:id" component={Foo} />
启动concent
之后,如果配置了路由,则history模块下的所有操作都将状态同步到了store的$$CONCENT_ROUTER
模块下,可以在console里打开输入sss回车并查看
1import { run, configureRoute } from 'react-router-concent'; 2 3// 启动concent 4run(); 5 6//配置路由,连击路由到store 7configureRoute();
1import React, { Component } from 'react' 2import ReactDOM from 'react-dom' 3import { BrowserRouter, Switch, Route } from 'react-router-dom'; 4import { ConnectRouter, history, Link } from 'react-router-concent'; 5import { run, register, CcFragment } from 'concent'; 6 7run(); 8 9class User extends Component { 10 $$setup(ctx) { 11 ctx.on('onUrlChanged', () => { 12 console.log(params); 13 this.init('onUrlChanged'); 14 }); 15 16 // mock componentDidMount 17 ctx.effect(() => { 18 this.init('componentDidMount'); 19 }, []); 20 } 21 init = (by) => { 22 console.log('%c init User, triggered by ' + by, 'color:red; border:1px solid red'); 23 } 24 render() { 25 return ( 26 <div style={{ border: '1px solid blue', margin: '19px' }}> 27 <h3>user</h3> 28 </div> 29 ); 30 } 31} 32const User_ = register('User')(User); 33 34class UserDetail extends Component { 35 $$setup(ctx) { 36 ctx.on('onUrlChanged', () => { 37 console.log(params); 38 this.init('onUrlChanged'); 39 }); 40 41 ctx.effect(() => { 42 this.init('componentDidMount'); 43 }, []); 44 } 45 init = (by) => { 46 console.log('%c init UserDetail, triggered by ' + by, 'color:red; border:1px solid red'); 47 } 48 render() { 49 return ( 50 <div> 51 <h3>user detail</h3> 52 </div> 53 ); 54 } 55} 56 57const UserDetail_ = register('UserDetail')(UserDetail); 58 59const setup = ctx => { 60 ctx.on('onUrlChanged', (params, action) => { 61 ctx.setState({ msg: 'url changed ' + Date.now() }); 62 }); 63} 64const iState = { msg: '' }; 65 66const F = () => ( 67 <CcFragment register={{setup,state:iState}} render={ctx => { 68 return <h1>fragment msg: {ctx.state.msg}</h1> 69 }} /> 70); 71 72function FnComp(){ 73 const ctx = useConcent({setup,state:iState}); 74 return <h1>fragment msg: {ctx.state.msg}</h1> 75} 76 77class Layout extends Component { 78 render() { 79 console.log('Layout Layout'); 80 return ( 81 <div> 82 <div onClick={() => history.push('/user')}>go to user page</div> 83 <div onClick={() => history.push('/user/55')}>go to userDetail page</div> 84 {/** 可以基于history主动push,也可以使用Link */} 85 <Link to="/user" onClick={to => alert(to)}>to user</Link> 86 <div onClick={() => history.push('/wow')}>fragment</div> 87 88 <Route path="/user" component={User_} /> 89 <Route path="/user/:id" component={UserDetail_} /> 90 <Route path="/wow" component={F} /> 91 <Route path="/fn-comp" component={FnComp} /> 92 </div> 93 ) 94 } 95} 96 97const App = () => ( 98 <BrowserRouter> 99 <div id="app-root-node"> 100 <ConnectRouter /> 101 <Route path="/" component={Layout} /> 102 </div> 103 </BrowserRouter> 104) 105ReactDOM.render(<App />, document.getElementById('root'));
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
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