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