refactor: implement lazy load and separate routes #1425

Closed
opened 2026-04-05 16:27:19 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @soknaly on 11/25/2023

Implement lazy load and separate routes

As the App.tsx is too long it will keep growing and will be hard to maintain also all routes with each page are not lazily loaded which will increase the size of the entry file.

To group and separate routes based on each main page, in react-router v6 we need to use the route with the main path and end with a wildcard to define as a root page. Example: /monitors which contains sub-routes like /monitors/:id, we can define the PageRoute in App.tsx as /monitors/* and only :id in the sub-route component. It might sounds
complicated but once we get used to it, it'll be easier and faster.

Here's the result before and after implementing lazy loading:

Before

before-lazy

After

after-lazy

Pull Request Checklist:

  • Please make sure all jobs pass before requesting a review.
  • Put closes #XXXX in your comment to auto-close the issue that your PR fixes (if such).
  • Have you lint your code locally before submission?
  • Did you write tests where appropriate?

Screenshots (if appropriate):

*Originally created by @soknaly on 11/25/2023* ### Implement lazy load and separate routes As the `App.tsx` is too long it will keep growing and will be hard to maintain also all routes with each page are not lazily loaded which will increase the size of the entry file. To group and separate routes based on each main page, in react-router v6 we need to use the route with the main path and end with a wildcard to define as a root page. Example: `/monitors` which contains sub-routes like `/monitors/:id`, we can define the `PageRoute` in `App.tsx` as `/monitors/*` and only `:id` in the sub-route component. It might sounds complicated but once we get used to it, it'll be easier and faster. Here's the result before and after implementing lazy loading: #### Before <img width="1083" alt="before-lazy" src="https://github.com/OneUptime/oneuptime/assets/20983608/9d4e2d7d-2b82-4f29-965d-954abf0d201c"> #### After <img width="1089" alt="after-lazy" src="https://github.com/OneUptime/oneuptime/assets/20983608/3e8af3a3-3b80-45be-8302-3a8451fd3960"> ### Pull Request Checklist: - [ ] Please make sure all jobs pass before requesting a review. - [ ] Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if such). - [x] Have you lint your code locally before submission? - [ ] Did you write tests where appropriate? ### Related Issue? ### Screenshots (if appropriate):
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/oneuptime#1425