@ossy/router-react 0.0.1-beta.4 → 0.0.9
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/CHANGELOG.md +64 -0
- package/LICENSE +21 -0
- package/build/cjs/index.js +1 -1
- package/build/esm/index.js +1 -1
- package/package.json +12 -6
- package/src/router-react.tsx +2 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## 0.0.9 (2025-10-25)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @ossy/router-react
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 0.0.8 (2025-10-25)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @ossy/router-react
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## 0.0.7 (2025-10-25)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @ossy/router-react
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## 0.0.6 (2025-10-25)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @ossy/router-react
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## 0.0.5 (2025-10-25)
|
|
39
|
+
|
|
40
|
+
**Note:** Version bump only for package @ossy/router-react
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## 0.0.4 (2025-10-25)
|
|
47
|
+
|
|
48
|
+
**Note:** Version bump only for package @ossy/router-react
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## 0.0.3 (2025-10-25)
|
|
55
|
+
|
|
56
|
+
**Note:** Version bump only for package @ossy/router-react
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
## 0.0.2 (2025-10-25)
|
|
63
|
+
|
|
64
|
+
**Note:** Version bump only for package @ossy/router-react
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ossy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/build/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("react"),n=require("@ossy/router"),r=function(){return r=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var a in n=arguments[r])Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a]);return e},r.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var t=e.createContext({pages:[],defaultLanguage:void 0,supportedLanguages:[]}),a=function(e){return void 0===e&&(e=""),function(e){return"/"===e[e.length-1]?e:"".concat(e,"/")}(function(e){return"/"===e[0]?e:"/".concat(e)}(e))};exports.Router=function(o){var i,u,l,d,c,s=o.url,f=o.pages,g=void 0===f?[]:f,p=o.defaultLanguage,v=void 0===p?void 0:p,w=o.supportedLanguages,h=void 0===w?[]:w;if(s){var m=s.match(/([^?#]*)(\?[^#]*)?(#.*)?/);u=s,l=(null==m?void 0:m[1])||"",d=(null==m?void 0:m[3])||"",c=(null==m?void 0:m[2])||""}else{if("undefined"==typeof window)return e.createElement(e.Fragment,null);u=window.location.href,l=window.location.pathname,c=(null==(d=window.location.hash)?void 0:d.includes("?"))?d.split("?")[1]:window.location.search}var y=h.length>1&&!!v,b=l.split("/")[1]||"",L=h.includes(b)?b:v,k=n.Router.of({pages:g,defaultLanguage:v,supportedLanguages:h}),P=k.getParamsFromUrl(u),R=new URLSearchParams(c),S=k.getPageByUrl(u);if(S||(y&&"/"===l&&"undefined"!=typeof window&&(window.location.href="/"+v),S=y?g.find(
|
|
1
|
+
"use strict";var e=require("react"),n=require("@ossy/router"),r=function(){return r=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var a in n=arguments[r])Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a]);return e},r.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var t=e.createContext({pages:[],defaultLanguage:void 0,supportedLanguages:[]}),a=function(e){return void 0===e&&(e=""),function(e){return"/"===e[e.length-1]?e:"".concat(e,"/")}(function(e){return"/"===e[0]?e:"/".concat(e)}(e))};exports.Router=function(o){var i,u,l,d,c,s=o.url,f=o.pages,g=void 0===f?[]:f,p=o.defaultLanguage,v=void 0===p?void 0:p,w=o.supportedLanguages,h=void 0===w?[]:w;if(s){var m=s.match(/([^?#]*)(\?[^#]*)?(#.*)?/);u=s,l=(null==m?void 0:m[1])||"",d=(null==m?void 0:m[3])||"",c=(null==m?void 0:m[2])||""}else{if("undefined"==typeof window)return e.createElement(e.Fragment,null);u=window.location.href,l=window.location.pathname,c=(null==(d=window.location.hash)?void 0:d.includes("?"))?d.split("?")[1]:window.location.search}var y=h.length>1&&!!v,b=l.split("/")[1]||"",L=h.includes(b)?b:v,k=n.Router.of({pages:g,defaultLanguage:v,supportedLanguages:h}),P=k.getParamsFromUrl(u),R=new URLSearchParams(c),S=k.getPageByUrl(u);if(S||(y&&"/"===l&&"undefined"!=typeof window&&(window.location.href="/"+v),S=y?g.find(function(e){return"*"===a(e.path[L])}):g.find(function(e){return"*"===a(e.path)})),!S)return console.warn("[RouterReact] No active page found for",l),e.createElement(e.Fragment,null);e.useCallback(function(e,n){if("undefined"!=typeof window){window.history.pushState({},"","".concat(l,"?").concat(R.toString()));var r=new URLSearchParams(R);r.set(e,n),history.pushState({},"","?".concat(r.toString()))}},[R]);var C=e.useCallback(function(e){var n,r,t,a,o,i={};if("string"==typeof e?(n=e,i=P,r=L):(o=e).id||void 0===o.language?(n=(null==e?void 0:e.id)||S.id,i=(null==e?void 0:e.params)||P,r=(null==e?void 0:e.language)||L):(n=S.id,i=P,r=e.language),n.includes("#")){var u=n.split("#");if(n=u[0],(t=u[1]).includes("?")){var l=n.split("?");t=l[0],a=l[1]}}else if(n.includes("?")){var d=n.split("?");n=d[0],a=d[1]}var c=k.getPathname({id:n.replace("@",""),params:i,language:r});return t&&(c=c+"#"+t),a&&(c=c+"?"+a),c},[k,L]),x=e.useCallback(function(e){if("undefined"!=typeof window&&e)if("@back"!==e){var n=C(e);n&&(window.location.href=n)}else window.history.back()},[C]),E=e.useCallback(function(){"undefined"!=typeof window&&window.history.back()},[]),U={href:u,pages:g,language:L,defaultLanguage:v,supportedLanguages:h,params:P,searchParams:r({},Array.from(R.entries()).reduce(function(e,n){var t,a=n[0],o=n[1];return r(r({},e),((t={})[a]=o,t))},{})),navigate:x,getHref:C,back:E};(null==S?void 0:S.redirect)&&x({id:S.redirect});var F=(null==S?void 0:S.element)||(null===(i=null==S?void 0:S.render)||void 0===i?void 0:i.call(S));return e.createElement(t.Provider,{value:U},F)},exports.RouterContext=t,exports.useRouter=function(){return e.useContext(t)};
|
package/build/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{createContext as n,useContext as r,useCallback as a}from"react";import{Router as t}from"@ossy/router";var o=function(){return o=Object.assign||function(e){for(var n,r=1,a=arguments.length;r<a;r++)for(var t in n=arguments[r])Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t]);return e},o.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var i=n({pages:[],defaultLanguage:void 0,supportedLanguages:[]}),u=function(){return r(i)},d=function(e){return void 0===e&&(e=""),function(e){return"/"===e[e.length-1]?e:"".concat(e,"/")}(function(e){return"/"===e[0]?e:"/".concat(e)}(e))},l=function(n){var r,u,l,c,s,f=n.url,g=n.pages,p=void 0===g?[]:g,v=n.defaultLanguage,w=void 0===v?void 0:v,h=n.supportedLanguages,m=void 0===h?[]:h;if(f){var y=f.match(/([^?#]*)(\?[^#]*)?(#.*)?/);u=f,l=(null==y?void 0:y[1])||"",c=(null==y?void 0:y[3])||"",s=(null==y?void 0:y[2])||""}else{if("undefined"==typeof window)return e.createElement(e.Fragment,null);u=window.location.href,l=window.location.pathname,s=(null==(c=window.location.hash)?void 0:c.includes("?"))?c.split("?")[1]:window.location.search}var L=m.length>1&&!!w,P=l.split("/")[1]||"",S=m.includes(P)?P:w,b=t.of({pages:p,defaultLanguage:w,supportedLanguages:m}),E=b.getParamsFromUrl(u),R=new URLSearchParams(s),k=b.getPageByUrl(u);if(k||(L&&"/"===l&&"undefined"!=typeof window&&(window.location.href="/"+w),k=L?p.find(
|
|
1
|
+
import e,{createContext as n,useContext as r,useCallback as a}from"react";import{Router as t}from"@ossy/router";var o=function(){return o=Object.assign||function(e){for(var n,r=1,a=arguments.length;r<a;r++)for(var t in n=arguments[r])Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t]);return e},o.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var i=n({pages:[],defaultLanguage:void 0,supportedLanguages:[]}),u=function(){return r(i)},d=function(e){return void 0===e&&(e=""),function(e){return"/"===e[e.length-1]?e:"".concat(e,"/")}(function(e){return"/"===e[0]?e:"/".concat(e)}(e))},l=function(n){var r,u,l,c,s,f=n.url,g=n.pages,p=void 0===g?[]:g,v=n.defaultLanguage,w=void 0===v?void 0:v,h=n.supportedLanguages,m=void 0===h?[]:h;if(f){var y=f.match(/([^?#]*)(\?[^#]*)?(#.*)?/);u=f,l=(null==y?void 0:y[1])||"",c=(null==y?void 0:y[3])||"",s=(null==y?void 0:y[2])||""}else{if("undefined"==typeof window)return e.createElement(e.Fragment,null);u=window.location.href,l=window.location.pathname,s=(null==(c=window.location.hash)?void 0:c.includes("?"))?c.split("?")[1]:window.location.search}var L=m.length>1&&!!w,P=l.split("/")[1]||"",S=m.includes(P)?P:w,b=t.of({pages:p,defaultLanguage:w,supportedLanguages:m}),E=b.getParamsFromUrl(u),R=new URLSearchParams(s),k=b.getPageByUrl(u);if(k||(L&&"/"===l&&"undefined"!=typeof window&&(window.location.href="/"+w),k=L?p.find(function(e){return"*"===d(e.path[S])}):p.find(function(e){return"*"===d(e.path)})),!k)return console.warn("[RouterReact] No active page found for",l),e.createElement(e.Fragment,null);a(function(e,n){if("undefined"!=typeof window){window.history.pushState({},"","".concat(l,"?").concat(R.toString()));var r=new URLSearchParams(R);r.set(e,n),history.pushState({},"","?".concat(r.toString()))}},[R]);var U=a(function(e){var n,r,a,t,o,i={};if("string"==typeof e?(n=e,i=E,r=S):(o=e).id||void 0===o.language?(n=(null==e?void 0:e.id)||k.id,i=(null==e?void 0:e.params)||E,r=(null==e?void 0:e.language)||S):(n=k.id,i=E,r=e.language),n.includes("#")){var u=n.split("#");if(n=u[0],(a=u[1]).includes("?")){var d=n.split("?");a=d[0],t=d[1]}}else if(n.includes("?")){var l=n.split("?");n=l[0],t=l[1]}var c=b.getPathname({id:n.replace("@",""),params:i,language:r});return a&&(c=c+"#"+a),t&&(c=c+"?"+t),c},[b,S]),F=a(function(e){if("undefined"!=typeof window&&e)if("@back"!==e){var n=U(e);n&&(window.location.href=n)}else window.history.back()},[U]),O=a(function(){"undefined"!=typeof window&&window.history.back()},[]),j={href:u,pages:p,language:S,defaultLanguage:w,supportedLanguages:m,params:E,searchParams:o({},Array.from(R.entries()).reduce(function(e,n){var r,a=n[0],t=n[1];return o(o({},e),((r={})[a]=t,r))},{})),navigate:F,getHref:U,back:O};(null==k?void 0:k.redirect)&&F({id:k.redirect});var x=(null==k?void 0:k.element)||(null===(r=null==k?void 0:k.render)||void 0===r?void 0:r.call(k));return e.createElement(i.Provider,{value:j},x)};export{l as Router,i as RouterContext,u as useRouter};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/router-react",
|
|
3
|
-
"
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"repository": "github:ossy-se/packages",
|
|
4
5
|
"description": "React router built for server side rendering and multi-language support with localized paths",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"react",
|
|
@@ -13,13 +14,14 @@
|
|
|
13
14
|
"prerendering",
|
|
14
15
|
"href",
|
|
15
16
|
"anchor",
|
|
16
|
-
"server"
|
|
17
|
+
"server",
|
|
18
|
+
"pages"
|
|
17
19
|
],
|
|
18
|
-
"version": "0.0.1-beta.4",
|
|
19
20
|
"source": "src/index.js",
|
|
20
21
|
"type": "module",
|
|
21
22
|
"main": "build/cjs/index.js",
|
|
22
23
|
"module": "build/esm/index.js",
|
|
24
|
+
"license": "MIT License",
|
|
23
25
|
"author": "Ossy <yourfriends@ossy.se> (https://ossy.se)",
|
|
24
26
|
"scripts": {
|
|
25
27
|
"build": "rollup -c rollup.config.js",
|
|
@@ -58,7 +60,11 @@
|
|
|
58
60
|
"tslib": "^2.8.1"
|
|
59
61
|
},
|
|
60
62
|
"peerDependencies": {
|
|
61
|
-
"@ossy/router": "0.0.1
|
|
62
|
-
"react": "
|
|
63
|
-
}
|
|
63
|
+
"@ossy/router": ">=0.0.1 <1.0.0",
|
|
64
|
+
"react": ">=19.0.0 <20.0.0"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
69
|
+
"gitHead": "4e30bab37fa7624b3260cca5b8154c5f863ed8bb"
|
|
64
70
|
}
|
package/src/router-react.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import React, { createContext, useContext, useCallback } from 'react'
|
|
3
|
-
import { MultiLanguagePage, Router as
|
|
3
|
+
import { MultiLanguagePage, Router as BaseRouter, RouterOptions, SingleLanguagePage, Page as _Page } from '@ossy/router'
|
|
4
4
|
|
|
5
5
|
export const RouterContext = createContext({
|
|
6
6
|
pages: [] as RouterPage[],
|
|
@@ -48,7 +48,7 @@ export const Router = <T extends RouterPage>({
|
|
|
48
48
|
const isMultiLanguage = supportedLanguages.length > 1 && !!defaultLanguage
|
|
49
49
|
const potentialLanguage = pathname.split('/')[1] || ''
|
|
50
50
|
const language = supportedLanguages.includes(potentialLanguage) ? potentialLanguage : defaultLanguage
|
|
51
|
-
const router =
|
|
51
|
+
const router = BaseRouter.of<T>({ pages, defaultLanguage, supportedLanguages })
|
|
52
52
|
const params = router.getParamsFromUrl(href)
|
|
53
53
|
const searchParams = new URLSearchParams(search)
|
|
54
54
|
|