Created
April 23, 2017 17:02
-
-
Save Metnew/65ee7939e4b9de1226a0e4c4cb4703d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns application routing with protected by AuthCheck func routes | |
* @param {Function} authCheck checks is user logged in | |
*/ | |
export const Routing = authCheck => { | |
// remove components that aren't application routes, (e.g. github link in sidebar) | |
let routes = appRouting.filter(a => a.tag || a.component) | |
// render components that are inside Switch (main view) | |
let routesRendered = routes.map((a, i) => { | |
// get tag for Route. is it RouteAuth `protected route` or Route? | |
let Tag = a.tag | |
let {path, exact, strict, component} = a | |
// can visitor access this route? | |
let canAccess = authCheck | |
// select only props that we need | |
let b = {path, exact, strict, component, canAccess} | |
return <Tag key={i} {...b} /> | |
}) | |
return ( | |
<App> | |
<Switch> | |
{routesRendered} | |
<Redirect to="/" /> | |
</Switch> | |
</App> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment