Routes with parameters
This commit is contained in:
parent
c29c5d78b2
commit
e8d6cee110
@ -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>} />
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user