0.2.7 • Published 5 years ago

saber-router v0.2.7

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

saber-router

npm

router.

# from npm
npm install saber-router

# from github
git clone https://github.com/Saber2pr/saber-router.git

API

useRoute

监听一个 url

参数:useRoute(url, callback)

返回值:Function,执行后取消对该 url 的监听

// 监听url: '/home'
const unUseRoute = useRoute('/home', () => alert('home'))
// 取消对'/home'的监听
unUseRoute()

useRoutes

监听一组 url

参数:useRoutes(obj),obj 属性是 url,值是 callback

返回值:Function,执行后取消对该组 url 的监听

const unUseRoutes = useRoutes({
  '/': () => alert(getHref()),
  '/home': () => alert(getHref()),
  '/home/test': () => alert(getHref()),
  '/project': () => alert(getHref()),
  '/about': () => alert(getHref())
})
// 取消监听
unUseRoutes()

push

发射路由事件

参数: push(url)或 push(url, data),第二个参数可以在 callback 参数中获取

push('/home')

push('/home', 'hello')

getHref

获取当前 url

push('/home')

getHref() // '/home'

For React

;<Anchor href="/home">home</Anchor>

// if use hooks, you should use useEffect to cleanup the subscribptions.
useEffect(() =>
  useRoutes({
    '/': () => {},
    '/home': () => {},
    '/home/test': () => {},
    '/project': () => {}
  })
)

start

npm install
npm start

npm run dev

npm run serve

Author: saber2pr

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago