6.1.34-alpha.0 • Published 8 months ago

@meniga/router v6.1.34-alpha.0

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

@meniga/router

Core is a library for handling routing and history

Exports


history, route

Customized versions of history from 'history' - This is not needed for react-router-6 and highly discouraged to use. This is only here temporarily while apps are being migrated to react-router v6.

Router

Customized versions of Router from 'react-router-dom' (v6) which includes a ScrollManager

BrowserRouter, MemoryRouter, HashRouter, RouterProvider, createBrowserRouter, createHashRouter, createMemoryRouter, createRoutesFromElements, Routes, Route, Link, Navigate, useLocation, useNavigate, useMatches, useMatch, useNavigation, useHref, useParams, useRoutes, useSearchParams, useRouteError,

Direct exports from react-router-dom (v6)

Getting started

This example shows you how to use the RouterProvider with routes as an array, but you can also use e.g. BrowserRouter directly and specify your routes as elements.

import React, { Fragment } from 'react'
import { createBrowserRouter, RouterProvider } from '@meniga/router'
import { routeConfig } from './routeConfig'
import { globalConfig } from '@meniga/config'

const _configBasename = globalConfig('routing.prefix', '')

const App = () => {
	const browserRouter = createBrowserRouter(routeConfig(), { basename: _configBasename })

	return <RouterProvider router={ browserRouter } />
}

export default App

Example routeConfig.js:

import React from 'react'

import { default as LayoutRoot } from './layouts/LayoutRoot'
import { default as LayoutError } from './layouts/LayoutError'
import { default as LayoutSimple } from './layouts/LayoutSimple'
import { default as LayoutDefault } from './layouts/LayoutDefault'

import Logout from './Logout'
import Login from './open/Login'
import Error503 from './Error503'
import Error404 from './Error404'
import NetworkError from './NetworkError'
import Protected from './protected/Protected'

export const routeConfig = () => {

	const errorRoutes = [
		{
			key: 'error503Route',
			element: <Error503 />,
			path: '/503'
		},
		{
			key: 'error404Route',
			element: <Error404 />,
			path: '/404'
		},
		{
			key: 'errorNetworkRoute',
			element: <NetworkError />,
			path: '/error'
		}
	]

	const simpleRoutes = [
		{
			key: 'logoutRoute',
			element: <Logout />,
			path: '/logout'
		},
		{
			key: 'loginRoute',
			path: '/login/:path?',
			element: <Login />
		}
	]

	const defaultRoutes = [
		{
			key: 'protectedRoutes',
			path: '/:page?/*?',
			element: <Protected />
		}
	]

	const routes = [
		{
			element: <LayoutRoot />,
			children: [
				{
					element: <LayoutError />,
					children: errorRoutes
				},
				{
					element: <LayoutSimple />,
					children: simpleRoutes
				},
				{
					element: <LayoutDefault />,
					children: defaultRoutes
				},
			]
		}		
	]

	return routes
}
6.1.34-alpha.0

8 months ago

6.1.33-alpha.0

8 months ago

6.1.32-alpha.0

8 months ago

6.1.30-alpha.0

8 months ago

6.1.31-alpha.0

8 months ago

6.1.27-alpha.0

9 months ago

6.1.28-alpha.0

8 months ago

6.1.29-alpha.0

8 months ago

6.1.26-alpha.0

9 months ago

6.1.19-alpha.0

10 months ago

6.1.23-alpha.0

9 months ago

6.1.20-alpha.0

10 months ago

6.1.21-alpha.0

9 months ago

6.1.22-alpha.0

9 months ago

6.1.16-alpha.0

12 months ago

6.1.17-alpha.0

12 months ago

6.1.13-alpha.0

12 months ago

6.1.12-alpha.0

1 year ago

6.1.14-alpha.0

12 months ago

6.1.15-alpha.0

12 months ago

6.1.25-alpha.0

9 months ago

6.1.24-alpha.0

9 months ago

6.1.11-alpha.0

1 year ago

6.1.10-alpha.0

1 year ago

6.1.9

1 year ago

6.1.8

1 year ago

6.1.4-alpha.0

1 year ago

6.1.1-alpha.0

1 year ago

6.1.3-alpha.0

1 year ago

6.1.6

1 year ago

6.1.5

1 year ago

6.1.2-alpha.0

1 year ago

6.1.7

1 year ago

6.0.37-alpha.0

1 year ago

6.1.0

1 year ago

6.0.38-alpha.0

1 year ago

6.0.36-alpha.0

1 year ago

6.0.35-alpha.0

1 year ago

6.0.34-alpha.0

1 year ago