Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. import * as React from "react";
  2. import { BrowserRouter as Router, Route, Switch, Link } from "react-router-dom";
  3. import { STRoute } from "../../components/routing/RouteBuilder";
  4. import AdminUser from "./admin-user";
  5. import AdminUsers from "./admin-users";
  6.  
  7. export type AdminAppDataProps = {
  8. }
  9. export type AdminAppActionProps = {
  10. }
  11.  
  12. export type AdminAppProps = AdminAppDataProps & AdminAppActionProps;
  13.  
  14. const ROOT = "/Admin/app";
  15. export const R_USERS = new STRoute<{ userId: number }>(`${ROOT}/users`, [{ key: "userId", optional: true }]);
  16.  
  17. //-- Alternative Declaration
  18. //export const R_USERS = STRoute.AllOptional<{ userId: number }>(`${ROOT}/users`, "userId");
  19.  
  20. const AdminApp: React.FC<AdminAppProps> = (props) => {
  21.  
  22. return (
  23. <div>
  24. <Router>
  25. <ul>
  26. <Switch>
  27. <Route path={R_USERS.RoutePath(true)} render={({ match }) => {
  28. return (
  29. <li>
  30. <Link to={R_USERS.RootLink()}>
  31. {`Users ${R_USERS.Params(match).userId}`}
  32. </Link>
  33. </li>
  34. );
  35. }} />
  36. <Route path={ROOT} render={() => (
  37. <li>
  38. <Link to={R_USERS.RootLink()}>
  39. {`Users`}
  40. </Link>
  41. </li>
  42. )} />
  43. </Switch>
  44. </ul>
  45.  
  46. <div>
  47. <div className={"pt-3 border-bottom border-right border-left px-1 px-lg-2"}>
  48. <Switch>
  49. <Route path={R_TAGS.RoutePath()} render={() => <AdminTags />} />
  50. <Route path={R_USERS.RoutePath()} render={({ match }) => {
  51. const { userId } = R_USERS.Params(match);
  52. if (userId) {
  53. return <AdminUser userId={parseInt(userId)} />;
  54. }
  55. return <AdminUsers />
  56. }} />
  57. <Route path={ROOT} render={() => (
  58. <div>
  59. <h3>{"Admin Portal"}</h3>
  60. <p>{"Welcome to the admin portal!"}</p>
  61. </div>
  62. )} >
  63. </Route>
  64. </Switch>
  65. </div>
  66. </div>
  67.  
  68. </Router>
  69. </div>
  70. );
  71. }
  72.  
  73.  
  74. export default AdminApp;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement