diff --git a/dist/index.d.ts b/dist/index.d.ts index 94b4300..92243a0 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,18 +1,18 @@ -import { match } from "react-router"; -import { RouteConfig } from "react-router-config"; -import { Location } from "history"; +import { PathMatch, RouteObject } from 'react-router'; +import { Location } from 'history'; export interface TitleObject { title: string; titles: string[]; - params: match["params"]; + params: PathMatch['params']; } declare type Routes = RouteConfigExtended[] | { [name: string]: RouteConfigExtended; }; -export interface RouteConfigExtended extends Omit { +export interface RouteConfigExtended extends Omit { title: string; titleConcat?: boolean; - routes?: Routes; + children?: Routes; + path: string; } export interface RouterTitleProps { routesConfig: Routes; diff --git a/dist/index.js b/dist/index.js index f5419d5..3e240ac 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7,13 +7,13 @@ const getRoute = (routesConfig, path) => { let currentMatch; if (Array.isArray(routesConfig)) { route = routesConfig.find((routeConfig) => { - currentMatch = react_router_1.matchPath(path, routeConfig); + currentMatch = (0, react_router_1.matchPath)(routeConfig, path); return currentMatch; }); } else { const id = Object.keys(routesConfig).find((key) => { - currentMatch = react_router_1.matchPath(path, routesConfig[key]); + currentMatch = (0, react_router_1.matchPath)(routesConfig[key], path); return currentMatch; }); route = routesConfig[id]; @@ -30,8 +30,8 @@ const getTitle = (routesConfig, path, divider, titles = [], matchCache) => { if (route.title) { titles.push(route.title); } - if (route.routes) { - return getTitle(route.routes, path, divider, titles, currentMatch || matchCache); + if (route.children) { + return getTitle(route.children, path, divider, titles, currentMatch || matchCache); } } return { @@ -40,9 +40,9 @@ const getTitle = (routesConfig, path, divider, titles = [], matchCache) => { params: currentMatch ? currentMatch.params : matchCache.params, }; }; -const RouterTitle = ({ pageTitle, routesConfig, callback = ({ title }) => title, divider = "·", prefix, }) => { - const location = react_router_1.useLocation(); - react_1.useEffect(() => { +const RouterTitle = ({ pageTitle, routesConfig, callback = ({ title }) => title, divider = '·', prefix, }) => { + const location = (0, react_router_1.useLocation)(); + (0, react_1.useEffect)(() => { Promise.resolve(callback(getTitle(routesConfig, location.pathname, divider, pageTitle && [pageTitle]), location)).then((title) => { document.title = prefix ? `${prefix}${title}` : title; }); diff --git a/dist/index.js.map b/dist/index.js.map index 84bf044..fcc5baf 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,iCAAkC;AAClC,+CAA6D;AAoB7D,MAAM,QAAQ,GAAG,CAAC,YAAoB,EAAE,IAAY,EAAuD,EAAE;IAC3G,IAAI,KAA0B,CAAC;IAC/B,IAAI,YAAmB,CAAC;IAExB,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QAC/B,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE;YACxC,YAAY,GAAG,wBAAS,CAAC,IAAI,EAAE,WAA0B,CAAC,CAAC;YAC3D,OAAO,YAAY,CAAC;QACtB,CAAC,CAAC,CAAC;KACJ;SAAM;QACL,MAAM,EAAE,GAAW,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;YACxD,YAAY,GAAG,wBAAS,CAAC,IAAI,EAAE,YAAY,CAAC,GAAG,CAAgB,CAAC,CAAC;YACjE,OAAO,YAAY,CAAC;QACtB,CAAC,CAAC,CAAC;QACH,KAAK,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;KAC1B;IAED,OAAO;QACL,KAAK;QACL,YAAY;KACb,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,CACf,YAAoB,EACpB,IAAY,EACZ,OAAe,EACf,SAAmB,EAAE,EACrB,UAAkB,EACL,EAAE;IACf,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAE7D,MAAM,iBAAiB,GAAG,CAAA,KAAK,aAAL,KAAK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AC,CAAC;AAEF,kBAAe,WAAW,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index 065a704..3906c00 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-router-title", - "version": "1.3.4", + "version": "6.0.0", "main": "dist/index.js", "types": "dist/index.d.ts", "author": "@lynoapp",