-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Login router problem #113
Comments
Hi @aolmez , Are you making it required for people to login before they can see contents in DefaultLayout component ? If so, here's some code:
I hope it helps. |
thanks for your answer
jeff-nz <notifications@github.com>, 25 Eyl 2018 Sal, 11:05 tarihinde şunu
yazdı:
… Hi @aolmez <https://github.com/aolmez> ,
Are you making it required for people to login before they can see
contents in DefaultLayout component ?
If so, here's some code:
const isAuthenticated = () => {
//write your condition here
return false;
}
const UnauthenticatedRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={(props) => (
!isAuthenticated()
? <Component {...props} />
: <Redirect to='/' />
)} />
);
const AuthenticatedRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={(props) => (
isAuthenticated()
? <Component {...props} />
: <Redirect to='/login' />
)} />
);
class App extends Component {
render() {
return (
<HashRouter>
<Switch>
<UnauthenticatedRoute exact path="/login" name="Login Page" component={Login} />
<Route exact path="/register" name="Register Page" component={Register} />
<Route exact path="/404" name="Page 404" component={Page404} />
<Route exact path="/500" name="Page 500" component={Page500} />
<AuthenticatedRoute path="/" name="Home" component={DefaultLayout} />
</Switch>
</HashRouter>
);
}
}
I hope it helps.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#113 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AJNc7Pjpf6M_X7RppCD40J8GQH8Mgwzvks5ueePigaJpZM4Wg6wP>
.
--
A.Kadir ÖLMEZ
|
I tried that using above scenario but after click login didn't redirect to homepage, my laptop's memory keep increasing and the browser suddenly turn unresposive page |
its worked man |
Thanks so much for this! @jeff-nz - would you advise to make all the non protected <HashRouter>
<React.Suspense fallback={loading()}>
<Switch>
<UnauthenticatedRoute exact path="/login" name="Login Page" component={Login} />
<UnauthenticatedRoute exact path="/register" name="Register Page" component={Register} />
<UnauthenticatedRoute exact path="/404" name="Page 404" component={Page404} />
<UnauthenticatedRoute exact path="/500" name="Page 500" component={Page500} />
<AuthenticatedRoute path="/" name="Home" component={DefaultLayout} />
</Switch>
</React.Suspense>
</HashRouter> |
getting error in prop type |
[UnauthenticatedRoute] is not a component. All component children of must be a or <React.Fragment>
Hi gettting this error |
I have same error, Redirect is removed from 'react-router-dom'. |
Hi
i want to route login page for opening page. How can make it ? i change router but return empty page.
can you help me ?
The text was updated successfully, but these errors were encountered: