@ossy/router-react 1.10.0 → 1.11.0
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.
- package/build/index.js +1 -1
- package/build/types/router-react.d.ts +2 -2
- package/package.json +2 -2
package/build/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{createContext as n,useCallback as a,useContext as r}from"react";import{Router as
|
|
1
|
+
import e,{createContext as n,useCallback as a,useContext as r}from"react";import{Router as i,isCatchAllRoutePath as o}from"@ossy/router";var t=function(){return t=Object.assign||function(e){for(var n,a=1,r=arguments.length;a<r;a++)for(var i in n=arguments[a])Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i]);return e},t.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var u=n({pages:[],defaultLanguage:void 0,supportedLanguages:[]}),l=function(){return r(u)},d=function(n){var r,l,d,s,c,f=n.url,p=n.pages,g=void 0===p?[]:p,v=n.defaultLanguage,w=void 0===v?void 0:v,h=n.supportedLanguages,m=void 0===h?[]:h,y=n.children;if(f){var L=f.match(/([^?#]*)(\?[^#]*)?(#.*)?/);l=f,d=(null==L?void 0:L[1])||"",s=(null==L?void 0:L[3])||"",c=(null==L?void 0:L[2])||""}else{if("undefined"==typeof window)return e.createElement(e.Fragment,null);l=window.location.href,d=window.location.pathname,c=(null==(s=window.location.hash)?void 0:s.includes("?"))?s.split("?")[1]:window.location.search}var P=m.length>1&&!!w,S=d.split("/")[1]||"",b=m.includes(S)?S:w,E=i.of({pages:g,defaultLanguage:w,supportedLanguages:m}),R=E.getParamsFromUrl(l),k=new URLSearchParams(c),U=E.getPageByUrl(l);if(U||(P&&"/"===d&&"undefined"!=typeof window&&(window.location.href="/"+w),U=P?g.find(function(e){var n,a=e.path,r=null!==(n=null==a?void 0:a[b])&&void 0!==n?n:null==a?void 0:a[w];return o(r)}):g.find(function(e){return o(e.path)})),!U)return console.warn("[RouterReact] No active page found for",d),e.createElement(e.Fragment,null);a(function(e,n){if("undefined"!=typeof window){window.history.pushState({},"","".concat(d,"?").concat(k.toString()));var a=new URLSearchParams(k);a.set(e,n),history.pushState({},"","?".concat(a.toString()))}},[k]);var F=a(function(e){var n,a,r,i,o,t={};if("string"==typeof e?(n=e,t=R,a=b):(o=e).id||void 0===o.language?(n=(null==e?void 0:e.id)||U.id,t=(null==e?void 0:e.params)||R,a=(null==e?void 0:e.language)||b):(n=U.id,t=R,a=e.language),n.includes("#")){var u=n.split("#");if(n=u[0],(r=u[1]).includes("?")){var l=n.split("?");r=l[0],i=l[1]}}else if(n.includes("?")){var d=n.split("?");n=d[0],i=d[1]}var s=E.getPathname({id:n.replace("@",""),params:t,language:a});return r&&(s=s+"#"+r),i&&(s=s+"?"+i),s},[E,b]),O=a(function(e){if("undefined"!=typeof window&&e)if("@back"!==e){var n=F(e);n&&(window.location.href=n)}else window.history.back()},[F]),j=a(function(){"undefined"!=typeof window&&window.history.back()},[]),x={href:l,pages:g,language:b,defaultLanguage:w,supportedLanguages:m,params:R,searchParams:t({},Array.from(k.entries()).reduce(function(e,n){var a,r=n[0],i=n[1];return t(t({},e),((a={})[r]=i,a))},{})),navigate:O,getHref:F,back:j};(null==U?void 0:U.redirect)&&O({id:U.redirect});var A=(null==U?void 0:U.element)||(null===(r=null==U?void 0:U.render)||void 0===r?void 0:r.call(U));return e.createElement(u.Provider,{value:x},y||A)};export{d as Router,u as RouterContext,l as useRouter};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
2
|
import { MultiLanguagePage, RouterOptions, SingleLanguagePage } from '@ossy/router';
|
|
3
3
|
export declare const RouterContext: React.Context<{
|
|
4
4
|
pages: RouterPage[];
|
|
@@ -10,7 +10,7 @@ export declare const useRouter: () => {
|
|
|
10
10
|
defaultLanguage: string | undefined;
|
|
11
11
|
supportedLanguages: string[];
|
|
12
12
|
};
|
|
13
|
-
export declare const Router: <T extends RouterPage>({ url, pages, defaultLanguage, supportedLanguages }: RouterProps<T
|
|
13
|
+
export declare const Router: <T extends RouterPage>({ url, pages, defaultLanguage, supportedLanguages, children }: PropsWithChildren<RouterProps<T>>) => React.JSX.Element;
|
|
14
14
|
export interface RouterProps<T extends RouterPage> extends RouterOptions<T> {
|
|
15
15
|
/**
|
|
16
16
|
* Render page associated with the given url.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/router-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/ossy-se/packages.git"
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"/build",
|
|
62
62
|
"README.md"
|
|
63
63
|
],
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "a151faf7a9af599b885ea98137575978fa1dffae"
|
|
65
65
|
}
|