Routes with parameters

This commit is contained in:
Federico Kereki 2018-07-25 23:16:39 -03:00
parent c29c5d78b2
commit e8d6cee110
4 changed files with 24 additions and 8 deletions

View File

@ -14,19 +14,31 @@ class App extends Component<{}> {
<BrowserRouter>
<Switch>
<Route path="/login" component={ConnectedLogin} />
<Route
path="/about/:something"
render={props => (
<div>
About... {props.match.params.something}
</div>
)}
/>
<Route
path="/help"
render={() => <div>Help!</div>}
/>
<ConnectedProtectedRoutes>
<Route
path="/"
exact
path="/"
render={() => <div>HOME SWEET HOME</div>}
/>
<Route
path="/AAA"
render={() => <div>AAA</div>}
path="/alpha"
render={() => <div>Alpha page</div>}
/>
<Route
path="/BBB"
render={() => <div>BBB</div>}
path="/zulu"
render={() => <div>Zulu page</div>}
/>
</ConnectedProtectedRoutes>
<Route render={() => <div>404 ERROR!</div>} />

View File

@ -21,7 +21,10 @@ export const loginFailure = () => ({
// Complex actions:
export const attemptLogin = (user, password) => async dispatch => {
export const attemptLogin = (
user: string,
password: string
) => async dispatch => {
try {
dispatch(loginRequest());
// the next line delays execution for 5 seconds:

View File

@ -11,6 +11,7 @@ export const ConnectedLogin = connect(
token: state.token
}),
dispatch => ({
onLogin: (user, password) => dispatch(attemptLogin(user, password))
onLogin: (user: string, password: string) =>
dispatch(attemptLogin(user, password))
})
)(Login);

View File

@ -12,7 +12,7 @@ export class ProtectedRoutes extends React.Component<{
static propTypes = {
token: PropTypes.string.isRequired,
children: PropTypes.arrayOf(PropTypes.object).isRequired,
location: PropTypes.object
location: PropTypes.object.isRequired
};
render() {