routes.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import App from "views/App";
  2. const errorLoading = error => {
  3. throw new Error(`Dynamic page loading failed: ${ error }`);
  4. };
  5. const loadRoute = cb => {
  6. return module => cb(null, module.default);
  7. };
  8. export default {
  9. path: "/",
  10. component: App,
  11. indexRoute: {
  12. getComponent(location, cb) {
  13. System.import("views/Home")
  14. .then(loadRoute(cb))
  15. .catch(errorLoading);
  16. },
  17. },
  18. childRoutes: [
  19. {
  20. path: "login",
  21. getComponent(location, cb) {
  22. System.import("views/Auth/Login")
  23. .then(loadRoute(cb, false))
  24. .catch(errorLoading);
  25. },
  26. },
  27. {
  28. path: "logout",
  29. getComponent(location, cb) {
  30. System.import("views/Auth/Logout")
  31. .then(loadRoute(cb, false))
  32. .catch(errorLoading);
  33. },
  34. },
  35. {
  36. path: "register",
  37. getComponent(location, cb) {
  38. System.import("views/Auth/Register")
  39. .then(loadRoute(cb, false))
  40. .catch(errorLoading);
  41. },
  42. },
  43. {
  44. path: "template",
  45. getComponent(location, cb) {
  46. System.import("views/Template")
  47. .then(loadRoute(cb, false))
  48. .catch(errorLoading);
  49. },
  50. },
  51. {
  52. path: "*",
  53. getComponent(location, cb) {
  54. System.import("views/NotFound")
  55. .then(loadRoute(cb))
  56. .catch(errorLoading);
  57. },
  58. },
  59. ],
  60. };