reboottime / Angular-Playbook

Crash angular for interview, now it's a repository works as a Angular playbook.
1 stars 0 forks source link

Routing in Angular Applications #33

Open reboottime opened 1 year ago

reboottime commented 1 year ago

Overview

This article discusses the routing essentials of large Angular applications, with content organized in two parts:


References

  1. lazy loading (lazy loading helps keep initial bundle sizes smaller, which in turn helps decrease load times.)
  2. Functional Guards ( replace deprecated CanActivate interface)
  3. Angular application folder structure guideline
reboottime commented 12 months ago

PART 1: URL Design Tips



An Example about SPA URL design

In this example, we are using the "orders" resource as a demonstration for designing URLs in an Angular Single Page Application (SPA).

reboottime commented 12 months ago

Part II: Common functional requirements on frontend routing

Authentication / RBAC on URL

In single page applications, route protection plays a critical role in ensuring secure access to different parts of the application. Let's consider the following two senariaos:

  1. A user attempts to access a specific URL within our Angular app. If the user isn't authenticated, the application's security mechanism kicks in, preventing unauthorized access.
  2. An invited external system user attempting to access an URL with sensitive data, for example, accessing organization's billing summaries.

For the above two cases,


URL redirection


Code Lazy Loading through URL Navigation on demand

A growing Single Page Application can be unwieldy. Without code splitting, the initial 'main.ts' can be overly large, slowing down the initial screen rendering.

Splitting code on based on routing could significantly reduce bundle size then reduces first screen rendering time.


Sample Code

reboottime commented 11 months ago

PART III: Code Organization and Routing

In single page application, features are best represented by distinct routing URL. Organizing features using modular approach allows developers to conveniently relocate code.

As it brings following benefits:


Sample Code: Organize Settings module

reboottime commented 11 months ago

References