Skip to content

react-router的增强功能,路由配置,异步路由拦截器

Notifications You must be signed in to change notification settings

xz1024/react-router-strong

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-router-strong

Install

npm install react-router-strong --save
 
import React from 'react'
import RouterStrong from 'react-router-strong'
import Home from '../views/Home'
import Layout from './views/Layout'
import Car from './views/Car'
import BWM from './views/BWM'
 

const config = [
    {
        path: "/app",
        component: Layout,
        redirect: '/app/home',
        children: [
            {
                path: '/app/home', aliasPath: ['/home'], component: Home
            },
            {
                path: '/app/car',
                component: Car,
                children: [
                    {
                        path: '/app/car/bwm', component: BWM
                    }
                ]
            },
        ]
    },
]

const sleep = (time) => new Promise((resolve) => {
    setTimeout(() => {
        resolve()
    }, time)
})

export default () => (
    <div className="app">
        <RouterStrong
            indexPath='/app/home'
            noFoundPath='/404'
            mode={'history'}
            isSwitch={true}
            config={config}
             beforeEach={async (to, from, next) => {
                await sleep(2000)
                next()
            }}
            afterEach={() => {
                console.log('--------------afterEach-----------------------')
            }}
        >
        </RouterStrong>
    </div>
);

About

react-router的增强功能,路由配置,异步路由拦截器

Resources

Stars

Watchers

Forks

Packages

No packages published