kitze / mobx-router

A simple router for MobX + React apps
509 stars 66 forks source link

Is this idiomatic ? #6

Closed jbrodriguez closed 8 years ago

jbrodriguez commented 8 years ago

I want to redirect an unauthorized user if he's deep linking into a private path without credentials.

This is working, but I'm wondering if it's the best way to do it.

const views = {
    home: new Route({ path: '/', component: <Home /> }),
    perms: new Route({
        path: '/private',
        component: <Private />,
        beforeEnter: (route, params, store) => {
            if (!store.app.isAuthorized) {
                store.router.goTo(views.home)
                return false
            }
        }
    })
}
kitze commented 8 years ago

Yes that is fine. What I want to do is make the hooks like "beforeEnter" accept an array of functions. In this case you can extract the "isAuthorized" function and just plug it into one of the arrays.

jbrodriguez commented 8 years ago

ok, got it ... will look for that change, thanks !