Guest User

Untitled

a guest
Nov 11th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. /**
  2. * Centralized routes config
  3. */
  4.  
  5. import * as React from "react";
  6. import { RouteProps as ReactRouteProps } from "react-router-dom";
  7.  
  8. import { isDev, isHMR } from "@app/utils/flags";
  9.  
  10. // dynamically import the route module
  11. export type importModuleFn = () => Promise<React.ComponentClass>;
  12.  
  13. // Navigation props
  14. export interface NavConfig {
  15. readonly label: string;
  16. readonly icon?: React.ComponentClass;
  17. readonly priority?: number; // occurrence order in the navigation (defaults to the position in the routes array)
  18. }
  19.  
  20. // meta tags for SEO (irrelevant if app sits behind auth, like in this example)
  21. export interface MetaConfig {
  22. readonly title: string; // <title>, <meta "twitter:title" & "og:title" & "itemprop.name">
  23. readonly description: string; // <meta "description" & "twitter:description" & "og:description" & "itemprop.description">
  24. readonly keywords?: string; // <meta "keywords">
  25. readonly imageURL: string; // <meta "twitter:image" & "og:image" & "itemprop.image" >
  26. }
  27.  
  28. // the base props for a route
  29. export interface RouteProps extends ReactRouteProps {
  30. readonly path: string;
  31. readonly nav?: NavConfig;
  32. readonly meta?: MetaConfig;
  33. readonly guarded: boolean;
  34. readonly importModule: importModuleFn;
  35. }
  36.  
  37. // an array of declared routes
  38. export type Routes = ReadonlyArray<RouteProps>;
  39.  
  40. // the default protected/unprotected routes to redirect to if the user is logged
  41. // in or not logged in respectively.
  42. export const DFLT_PROTECTED_ROUTE = "/";
  43. export const DFLT_UNPROTECTED_ROUTE = "/login";
  44.  
  45. if (isDev && isHMR) {
  46. // pre-import routes during development so they can be hot-reloaded
  47. import("@app/routes/Dashboard");
  48. import("@app/routes/Account");
  49. import("@app/routes/Settings");
  50. import("@app/routes/Login");
  51. import("@app/routes/Register");
  52. import("@app/routes/ResendCfmCode");
  53. import("@app/routes/ResetPassword");
  54. import("@app/routes/NotFound");
  55. }
  56.  
  57. const routes: Routes = [
  58. {
  59. path: DFLT_PROTECTED_ROUTE, // default protected route is the dashboard page
  60. exact: true,
  61. guarded: true,
  62. nav: { label: "Dashboard", icon: undefined },
  63. importModule: async () => (await import("@app/routes/Dashboard")).default
  64. },
  65. {
  66. path: "/account",
  67. guarded: true,
  68. nav: { label: "Profile", icon: undefined },
  69. importModule: async () => (await import("@app/routes/Account")).default
  70. },
  71. {
  72. path: "/settings",
  73. guarded: true,
  74. nav: { label: "Settings", icon: undefined },
  75. importModule: async () => (await import("@app/routes/Settings")).default
  76. },
  77. {
  78. path: DFLT_UNPROTECTED_ROUTE, // default unprotected route is the login page
  79. guarded: false,
  80. nav: { label: "Login" },
  81. importModule: async () => (await import("@app/routes/Login")).default
  82. },
  83. {
  84. path: "/register",
  85. guarded: false,
  86. nav: { label: "Register" },
  87. importModule: async () => (await import("@app/routes/Registration")).default
  88. },
  89. {
  90. path: "/resend-confirmation-code",
  91. guarded: false,
  92. nav: { label: "Resend Confirmation Code" },
  93. importModule: async () => (await import("@app/routes/ResendCfmCode")).default
  94. },
  95. {
  96. path: "/reset-password",
  97. guarded: false,
  98. nav: { label: "Forgot something?" },
  99. importModule: async () => (await import("@app/routes/ResetPassword")).default
  100. },
  101. {
  102. path: "/404",
  103. guarded: false,
  104. importModule: async () => (await import("@app/routes/NotFound")).default
  105. }
  106. ];
  107.  
  108. export default routes;
Add Comment
Please, Sign In to add comment