@@ -9,27 +9,33 @@ const RelativeRouter = ({ children, _usemodule_in_design }) =>{
99 const routes = [ ] ;
1010 children . forEach ( child => {
1111 if ( child . props && child . props . path && typeof ( child . props . path ) === "string" ) {
12- routes . push ( { path : child . props . path , element : child } ) ;
12+ routes . push ( { path : child . props . path , element : React . createElement ( React . Fragment , null , child . props . children ) } ) ;
1313 }
1414 } ) ;
1515 return useRoutes ( routes ) ;
1616 } else {
1717 children . forEach ( child => {
1818 if ( child . props && Array . isArray ( child . props . children ) ) {
1919 child . props . children = child . props . children . map ( c => {
20- const { children, ...others } = c . props ;
21- return ( c . props && ! / ^ [ A B ] _ / . test ( c . props . id ) && c . props . path ) ? React . createElement ( "div" ,
22- { ...others , style :{ border :'dotted #444 1px' , padding :"4px" , margin :"4px" , background :( c . props . _usemodule_lastsel ?"#fffbd4" :"" ) } } ,
23- ! c . props . _usemodule_lastsel
24- ? "{ path : '" + ( c . props . path || "" ) + "', title : '" + ( c . props . title || "" ) + "', component: <" + c . props . _usemodule_vartag + ">" + ( children && children . length === 1 && children [ 0 ] && children [ 0 ] . type === 'usemoduletext' ?children [ 0 ] . props . children [ 0 ] :"..." ) + "</" + c . props . _usemodule_vartag + "> }"
25- : c
26- ) : c ;
27- } )
20+ let { children, ...others } = c . props ;
21+ if ( others && ! / ^ [ A B ] _ / . test ( others . id ) && others . path ) {
22+ if ( ! Array . isArray ( children ) ) children = [ children ] ;
23+ children . unshift ( React . createElement ( "div" ,
24+ { style :{ 'font-size' :'75%' , border :'dashed #444 1px' , padding :"4px" , margin :"4px 0" , background :others . _usemodule_lastsel ?"#fffbd4" :"" } } ,
25+ "{ path : '" + ( others . path || "" ) + "', title : '" + ( others . title || "" ) + "', component: <" + others . _usemodule_vartag + ">" + ( children && children . length === 1 && children [ 0 ] && children [ 0 ] . type === 'usemoduletext' ?children [ 0 ] . props . children [ 0 ] :"..." ) + "</" + others . _usemodule_vartag + "> }"
26+ ) ) ;
27+ return React . createElement ( "div" , others , others . _usemodule_lastsel ? children : children [ 0 ] ) ;
28+ } else {
29+ return c ;
2830 }
2931 } ) ;
30- return React . createElement ( "div" , { style :{ "font-size" :"75%" , border :'dashed #444 1px' , padding :"4px" , margin :"4px" } } , children ) ;
32+ }
33+ } ) ;
34+ return React . createElement ( "div" , null , children ) ;
3135 }
3236} ;
37+ RelativeRouter . _usemodule_nowrap = 1 ;
38+ RelativeRouter . _usemodule_nostyle = 1 ;
3339
3440const useRouter = ( ) => {
3541 const params = useParams ( ) ;
@@ -38,15 +44,24 @@ const useRouter = () => {
3844 const navigate = useNavigate ( ) ;
3945
4046 return React . useMemo ( ( ) => {
41- return { params, searchParams, setSearchParams, location, navigate, replace : route => navigate ( route , { replace : true } ) } ;
47+ return { params, searchParams, setSearchParams, location, navigate,
48+ pathname : location . pathname ,
49+ relativePath : "/" + params [ "*" ] . split ( "/" ) . pop ( ) ,
50+ query : {
51+ ...useModule . utils . getURLParams ( location . search ) ,
52+ ...params
53+ } ,
54+ push : route => navigate ( route ) ,
55+ replace : route => navigate ( route , { replace : true } )
56+ } ;
4257 } , [ params , searchParams , setSearchParams , location , navigate ] ) ;
4358} ;
4459
4560useModule . statePlugIn ( "router" , module => {
4661 const opt = module . options ;
4762 if ( opt . props && opt . props . router ) {
4863 return opt . _usemodule_in_design
49- ? { params :{ } , searchParams :{ } , setSearchParams :( searchParams ) => { } , location :{ hash : "" , key : "default" , pathname : "/" , search : "" , state : null } , navigate :( route , option ) => { } , replace :( route ) => { } }
64+ ? { params :{ } , searchParams :{ } , setSearchParams :( searchParams ) => { } , location :{ hash : "" , key : "default" , pathname : "/" , search : "" , state : null } , pathname : "/" , relativePath : "/" , query : { "*" : "/" } , navigate :( route , option ) => { } , push : ( route ) => { } , replace :( route ) => { } }
5065 : useRouter ( ) ;
5166 }
5267} ) ;
0 commit comments