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
+17 -5
View File
@@ -14,19 +14,31 @@ class App extends Component<{}> {
<BrowserRouter> <BrowserRouter>
<Switch> <Switch>
<Route path="/login" component={ConnectedLogin} /> <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> <ConnectedProtectedRoutes>
<Route <Route
path="/"
exact exact
path="/"
render={() => <div>HOME SWEET HOME</div>} render={() => <div>HOME SWEET HOME</div>}
/> />
<Route <Route
path="/AAA" path="/alpha"
render={() => <div>AAA</div>} render={() => <div>Alpha page</div>}
/> />
<Route <Route
path="/BBB" path="/zulu"
render={() => <div>BBB</div>} render={() => <div>Zulu page</div>}
/> />
</ConnectedProtectedRoutes> </ConnectedProtectedRoutes>
<Route render={() => <div>404 ERROR!</div>} /> <Route render={() => <div>404 ERROR!</div>} />
+4 -1
View File
@@ -21,7 +21,10 @@ export const loginFailure = () => ({
// Complex actions: // Complex actions:
export const attemptLogin = (user, password) => async dispatch => { export const attemptLogin = (
user: string,
password: string
) => async dispatch => {
try { try {
dispatch(loginRequest()); dispatch(loginRequest());
// the next line delays execution for 5 seconds: // the next line delays execution for 5 seconds:
+2 -1
View File
@@ -11,6 +11,7 @@ export const ConnectedLogin = connect(
token: state.token token: state.token
}), }),
dispatch => ({ dispatch => ({
onLogin: (user, password) => dispatch(attemptLogin(user, password)) onLogin: (user: string, password: string) =>
dispatch(attemptLogin(user, password))
}) })
)(Login); )(Login);
@@ -12,7 +12,7 @@ export class ProtectedRoutes extends React.Component<{
static propTypes = { static propTypes = {
token: PropTypes.string.isRequired, token: PropTypes.string.isRequired,
children: PropTypes.arrayOf(PropTypes.object).isRequired, children: PropTypes.arrayOf(PropTypes.object).isRequired,
location: PropTypes.object location: PropTypes.object.isRequired
}; };
render() { render() {