Skip to content

Releases: cher-ami/router

v2.0.0-beta-9

20 Jan 23:25
Compare
Choose a tag to compare

Fix #86 bug when a route is defined after a route witch contains subroutes.

{
    path: "/",
    component: HomePage,
  },
  {
    path: "/about",
    component: AboutPage,
    children: [
      {
        path: "/foo",
        component: FooPage,
      },
      {
        path: "/bar",
        component: BarPage,
       }
    ],
  },
 // this last route is now properly rendered
 {
    path: "/last",
    component: LastPage,
  },
}

v2.0.0-beta-8.1

09 Dec 09:38
Compare
Choose a tag to compare
v2.0.0-beta-8.1 Pre-release
Pre-release

Structure improvement

  • (Replace eventEmitter by React context #65)
    Using react context API, it's one less external tool to use in the project.

  • (Internalize router manager in router #79)
    There is no more RouterManager class instantiated in Router.tsx. All the route changing listening is made inside Router.tsx who call external matcher helper function. It's now easier to test this matcher function an avoids having to communicate between the independent Router instance and the react Router component.

  • (Update debug and dev server dependencies #74)
    Replace debug lib by the smaller lib @wbe/debug

Features

  • (Replace path-parser by path-to-regexp #75)
    path-to-regexp allows optional params witch was not possible with path-parser. route path can be now defined as /path/:id?. /path and /path/hello will match.

  • (Infinit sub Routers #79)
    It was working on one level, it's now possible to nest as many routers as needed.

  • new helpercreateUrl()
    Create a formated URL by string, or TOpenRouteParams. This method is available everywhere inside component.

import { createUrl } from "@cher-ami/router"
createUrl({ name: "ArticlePage", params: {id: "foo"} }) // will return a path as `/articles/foo` (depend of route paths)
  • new helper openRoute()
    Push new route in current history. Stack(s) component(s) will return the appropriate route. This method is available everywhere inside component.
import { openRoute } from "@cher-ami/router"
openRoute({ name: "ArticlePage", params: {id: "foo"} }) // stack will render the appropriate component
  • (add Setlang hook #81)
    If LangService instance is set to the Router, we can use this hook to quickly get current language and change language.
const [lang, setLang] = useLang();
  • (extended Link props with anchor html attributes #78)

  • (Export type #83)
    Expose TRoute type

  • (Expose routers #76)
    Global Routers object is now exposed. It contains informations available for all routers instances.

  • (Use microbundle instead of TSC #77 #82)

breaking changes

useRouter

  • useRoute() as been removed. currentRoute & previousRoute are now available from useRouter()
// before
const { currentRoute, previousRoute } = useRoute();
// v2
const { currentRoute, previousRoute } = useRouter();

LangService

  • LangService is now set to the router as an independent instance.
// before - it was a singleton
LangService.init([{ key: "en" }, { key: "fr" }], true, "/")
// ...
<Router middlewares={langMiddleware}> ... </Router>

// v2 - independent instance
const langService = new LangService({
  languages: [{ key: "en" }, { key: "fr" }],
  showDefaultLangInUrl: true,
  base: "/",
});
// ...
<Router langService={langService}> ... </Router>

Sub Router

Sub Router declaration is not as automatic and"magical" as before. In v2, we need to define manually what is the sub router base & routes.
getPathByRouteName, getSubRoutersBase & getSubRoutersRoutes are available to help use.

// before - we deduced internally what was sub routes and full base URL.
<Router base={"/foo"}>
</Router>

// v2

  // Get parent router context
  const { base, routes } = useRouter();

  // Parsed routes list and get path by route name
  const path = getPathByRouteName(routesList, "FooPage"); // "/foo"
  // ...
  return (
    <div>
      <Router
        // -> "/base/:lang/foo" (if last param is false, ':lang' will be not added)
        base={getSubRoutersBase(path, base, true)}
        // children routes array of FooPage
        routes={getSubRoutersRoutes(path, routes)}
      >
        <Stack />
      </Router>
    </div>
  );

useHistory

useHistory hook is returning now the whole of history object instead of an array of history location.

const history = useHistory(()=> {
}, [])
//...
history.push() // etc...

v2.0.0-beta-5

30 Nov 14:53
Compare
Choose a tag to compare
v2.0.0-beta-5 Pre-release
Pre-release

Features

  • (#65) Replace eventEmitter by React context
  • (#74) Update debug and dev server dependencies
  • (#75) Replace path-parser by path-to-regex
  • (#76) Expose routers and helpers:createUrl(), openRoute()
  • (#77) Use microbundle instead of TSC

breaking changes

  • useRoute() as been removed. currentRoute & previousRoute are now available from useRouter()
// before
const { currentRoute, previousRoute } = useRoute();

// v2
const { currentRoute, previousRoute } = useRouter();

v1.1.0

06 Sep 15:24
Compare
Choose a tag to compare

fix #68 breaking change

Change historyMode props (enum) to history props (BrowserHistory | HashHistory | MemoryHistory)

Now we need to create history and pass it as Router props. This props remains optional and createBrowserHistory() as default.

Before:

// ...
function App() {
  return (
    <Router routes={...} historyMode={EHistoryMode.BROWSER}>
     // ...
    </Router>
  );
}

Now:

// ...
import { createBrowserHistory } from "history";
const history = createBrowserHistory();

function App() {
  return (
    <Router routes={...} history={history}>
     // ...
    </Router>
  );
}

v1.0.0

18 May 09:55
Compare
Choose a tag to compare

Router is finally out as first major version 🎉

feature

  • Accept translated path (#58)
    Need before first release, it's now possible to set translate path by lang :
// string
path : "/foo"

// object
path { fr:"foo-fr", de:"foo-de", en:"foo-en" }

fix

  • Fix path if base is / with langservice setLang (#66)

v1.0.0-alpha.7

19 Apr 12:39
Compare
Choose a tag to compare

1.0.0-alpha.7

  • Fix stack prev and current key name (#62)
  • Remove unused debug (#57)
  • Install size-limit + Update size-limit job (#56)
  • Remove use lang hook (#54)

v1.0.0-alpha.6

09 Apr 10:08
Compare
Choose a tag to compare
  • Current route match returns route name (#46)
  • Link to pass obj (#47)
  • Fix not found route (#49)
  • CreateRouter unit tests (#51)

v1.0.0-alpha.5

07 Apr 14:17
Compare
Choose a tag to compare
  • Rename RouterInstance to CreateRouter (#42)
  • Modify LangService singleton export (#41)

v1.0.0-alpha.4

18 Mar 21:51
Compare
Choose a tag to compare
  • Create language service & middleware + tests (#29)

v1.0.0-alpha.3

11 Feb 11:07
Compare
Choose a tag to compare
  • Fix default location state (#37)
  • Change debug keyname (#34)