Browse Source

Merge pull request #25245 from abpframework/EngincanV/modern-template-cli

docs: React UI (CLI & UI Framework docs)
pull/25374/head
Enis Necipoglu 2 weeks ago
committed by GitHub
parent
commit
ec95acd2ae
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 971
      docs/en/cli/index.md
  2. 10
      docs/en/docs-nav.json
  3. 3
      docs/en/framework/ui/index.md
  4. 46
      docs/en/framework/ui/mvc-razor-pages/overall.md
  5. 74
      docs/en/framework/ui/react-native/index.md
  6. 439
      docs/en/framework/ui/react/index.md

971
docs/en/cli/index.md

File diff suppressed because it is too large

10
docs/en/docs-nav.json

@ -1866,6 +1866,16 @@
}
]
},
{
"text": "React",
"items": [
{
"text": "Overview",
"path": "framework/ui/react/index.md",
"isIndex": true
}
]
},
{
"text": "React Native",
"items": [

3
docs/en/framework/ui/index.md

@ -1,7 +1,7 @@
```json
//[doc-seo]
{
"Description": "Explore ABP's UI options, including MVC, Blazor, Angular, React Native, and MAUI, to build dynamic applications effortlessly."
"Description": "Explore ABP's UI options, including React, MVC, Blazor, Angular, React Native, and MAUI, to build dynamic applications effortlessly."
}
```
@ -9,6 +9,7 @@
ABP provides several options for building the user interface (UI) in your applications. Here are some of the officially supported UI options you can use with ABP:
* [React](./react/index.md) *(modern template system only)*
* [MVC / Razor Pages](./mvc-razor-pages/overall.md)
* [Blazor](./blazor/overall.md)
* [Angular](./angular/quick-start.md)

46
docs/en/framework/ui/mvc-razor-pages/overall.md

@ -17,8 +17,8 @@ ABP provides a convenient and comfortable way of creating web applications using
ASP.NET Core provides two models for UI development:
* **[MVC (Model-View-Controller)](https://docs.microsoft.com/en-us/aspnet/core/mvc/)** is the classic way that exists from the version 1.0. This model can be used to create UI pages/components and HTTP APIs.
* **[Razor Pages](https://docs.microsoft.com/en-us/aspnet/core/razor-pages/)** was introduced with the ASP.NET Core 2.0 as a new way to create web pages.
- **[MVC (Model-View-Controller)](https://docs.microsoft.com/en-us/aspnet/core/mvc/)** is the classic way that exists from the version 1.0. This model can be used to create UI pages/components and HTTP APIs.
- **[Razor Pages](https://docs.microsoft.com/en-us/aspnet/core/razor-pages/)** was introduced with the ASP.NET Core 2.0 as a new way to create web pages.
**ABP supports both** of the MVC and the Razor Pages models. However, it is suggested to create the **UI pages with Razor Pages** approach and use the **MVC model to build HTTP APIs**. So, all the pre-build modules, samples and the documentation is based on the Razor Pages for the UI development, while you can always apply the MVC pattern to create your own pages.
@ -32,18 +32,18 @@ The [application startup template](../../../solution-templates/application-modul
ABP provides a complete [Theming](theming.md) system with the following goals:
* Reusable [application modules](../../../modules) are developed **theme-independent**, so they can work with any UI theme.
* UI theme is **decided by the final application**.
* The theme is distributed via NuGet/NPM packages, so it is **easily upgradable**.
* The final application can **customize** the selected theme.
- Reusable [application modules](../../../modules) are developed **theme-independent**, so they can work with any UI theme.
- UI theme is **decided by the final application**.
- The theme is distributed via NuGet/NPM packages, so it is **easily upgradable**.
- The final application can **customize** the selected theme.
### Current Themes
Currently, three themes are **officially provided**:
* The [Basic Theme](Basic-Theme.md) is the minimalist theme with the plain Bootstrap style. It is **open source and free**.
* The [Lepton Theme](https://abp.io/themes) is a **commercial** theme developed by the core ABP team and is a part of the [ABP](https://abp.io/) license.
* The [LeptonX Theme](https://x.leptontheme.com/) is a theme that has both [commercial](../../../ui-themes/lepton-x/mvc.md) and [lite](../../../ui-themes/lepton-x-lite/asp-net-core.md) choices.
- The [Basic Theme](Basic-Theme.md) is the minimalist theme with the plain Bootstrap style. It is **open source and free**.
- The [Lepton Theme](https://abp.io/themes) is a **commercial** theme developed by the core ABP team and is a part of the [ABP](https://abp.io/) license.
- The [LeptonX Theme](https://x.leptontheme.com/) is a theme that has both [commercial](../../../ui-themes/lepton-x/mvc.md) and [lite](../../../ui-themes/lepton-x-lite/asp-net-core.md) choices.
There are also some community-driven themes for the ABP (you can search on the web).
@ -72,7 +72,7 @@ You can use these libraries directly in your applications, without needing to ma
The themes provide the standard layouts. So, you have responsive layouts with the standard features already implemented. The screenshot below has taken from the Application Layout of the [Basic Theme](basic-theme.md):
![basic-theme-application-layout](../../../images/basic-theme-account-layout.png)
basic-theme-application-layout
See the [Theming](theming.md) document for more layout options and other details.
@ -90,13 +90,13 @@ Dynamic JavaScript API Client Proxy system allows you to consume your server sid
**Example: Get a list of authors from the server**
````js
```js
acme.bookStore.authors.author.getList({
maxResultCount: 10
}).then(function(result){
console.log(result.items);
});
````
```
`acme.bookStore.authors.author.getList` is an auto-generated function that internally makes an AJAX call to the server.
@ -108,7 +108,7 @@ ABP makes it easier & type safe to write Bootstrap HTML.
**Example: Render a Bootstrap modal**
````html
```html
<abp-modal>
<abp-modal-header title="Modal title" />
<abp-modal-body>
@ -116,7 +116,7 @@ ABP makes it easier & type safe to write Bootstrap HTML.
</abp-modal-body>
<abp-modal-footer buttons="@(AbpModalButtons.Save|AbpModalButtons.Close)"></abp-modal-footer>
</abp-modal>
````
```
See the [Tag Helpers](tag-helpers) document for more.
@ -126,9 +126,9 @@ ABP provides `abp-dynamic-form` and `abp-input` tag helpers to dramatically simp
**Example: Use `abp-dynamic-form` to create a complete form based on a model**
````html
```html
<abp-dynamic-form abp-model="Movie" submit-button="true" />
````
```
See the [Forms & Validation](forms-validation.md) document for details.
@ -136,14 +136,14 @@ See the [Forms & Validation](forms-validation.md) document for details.
ABP provides a flexible and modular Bundling & Minification system to create bundles and minify style/script files on runtime.
````html
```html
<abp-style-bundle>
<abp-style src="/libs/bootstrap/css/bootstrap.css" />
<abp-style src="/libs/font-awesome/css/font-awesome.css" />
<abp-style src="/libs/toastr/toastr.css" />
<abp-style src="/styles/my-global-style.css" />
</abp-style-bundle>
````
```
Also, Client Side Package Management system offers a modular and consistent way of managing 3rd-party library dependencies.
@ -157,11 +157,11 @@ See the [Bundling & Minification](bundling-minification.md) and [Client Side Pac
ABP provides a lot of built-in solutions to common application requirements;
* [Widget System](widgets.md) can be used to create reusable widgets & create dashboards.
* [Page Alerts](page-alerts.md) makes it easy to show alerts to the user.
* [Modal Manager](modals.md) provides a simple way to build and use modals.
* [Data Tables](data-tables.md) integration makes straightforward to create data grids.
- [Widget System](widgets.md) can be used to create reusable widgets & create dashboards.
- [Page Alerts](page-alerts.md) makes it easy to show alerts to the user.
- [Modal Manager](modals.md) provides a simple way to build and use modals.
- [Data Tables](data-tables.md) integration makes straightforward to create data grids.
## Customization
There are a lot of ways to customize the theme and the UIs of the pre-built modules. You can override components, pages, static resources, bundles and more. See the [User Interface Customization Guide](customization-user-interface.md).
There are a lot of ways to customize the theme and the UIs of the pre-built modules. You can override components, pages, static resources, bundles and more. See the [User Interface Customization Guide](customization-user-interface.md).

74
docs/en/framework/ui/react-native/index.md

@ -5,12 +5,12 @@
}
```
````json
```json
//[doc-params]
{
"Architecture": ["Monolith", "Tiered", "Microservice"]
}
````
```
# Getting Started with React Native
@ -18,7 +18,7 @@
The ABP platform provides a basic [React Native](https://reactnative.dev/) startup template to develop mobile applications **integrated with your ABP-based backends**.
![React Native gif](../../../images/react-native-introduction.gif)
React Native gif
## How to Prepare Development Environment
@ -28,10 +28,9 @@ Please follow the steps below to prepare your development environment for React
2. **[Optional] Install Yarn:** You can install Yarn v1 (not v2) by following the instructions on [the installation page](https://classic.yarnpkg.com/en/docs/install). Yarn v1 provides a better developer experience compared to npm v6 and below. You can skip this step and use npm, which is built into Node.js.
3. **[Optional] Install VS Code:** [VS Code](https://code.visualstudio.com/) is a free, open-source IDE that works seamlessly with TypeScript. While you can use any IDE, including Visual Studio or Rider, VS Code typically provides the best developer experience for React Native projects.
4. **[Optional] Install an Emulator/Simulator:** If you want to test on Android emulators or iOS simulators (instead of using the Web View method), you'll need to install one of the following:
- **Android Studio & Emulator:** Install [Android Studio](https://developer.android.com/studio) and set up an Android Virtual Device (AVD) through the AVD Manager. You can follow the [Android Studio Emulator guide](https://docs.expo.dev/workflow/android-studio-emulator/) on expo.io documentation.
- **Xcode & iOS Simulator:** On macOS, install [Xcode](https://developer.apple.com/xcode/) from the App Store, which includes the iOS Simulator. You can follow the [iOS Simulator guide](https://docs.expo.dev/workflow/ios-simulator/) on expo.io documentation.
> **Note:** The Web View method (recommended for quick testing) doesn't require an emulator or simulator. If you prefer a CLI-based approach for Android, you can check the [setting up android emulator without android studio](setting-up-android-emulator.md) guide as an alternative.
- **Android Studio & Emulator:** Install [Android Studio](https://developer.android.com/studio) and set up an Android Virtual Device (AVD) through the AVD Manager. You can follow the [Android Studio Emulator guide](https://docs.expo.dev/workflow/android-studio-emulator/) on expo.io documentation.
- **Xcode & iOS Simulator:** On macOS, install [Xcode](https://developer.apple.com/xcode/) from the App Store, which includes the iOS Simulator. You can follow the [iOS Simulator guide](https://docs.expo.dev/workflow/ios-simulator/) on expo.io documentation.
> **Note:** The Web View method (recommended for quick testing) doesn't require an emulator or simulator. If you prefer a CLI-based approach for Android, you can check the [setting up android emulator without android studio](setting-up-android-emulator.md) guide as an alternative.
## How to Start a New React Native Project
@ -41,7 +40,7 @@ You have multiple options to initiate a new React Native project that works with
ABP Studio is the most convenient and flexible way to create a React Native application based on the ABP framework. Follow the [tool documentation](../../../studio) and select the option below:
![React Native option](../../../images/react-native-option.png)
React Native option
### 2. Using ABP CLI
@ -61,7 +60,6 @@ This command creates a solution containing an **Angular** or **MVC** project (de
Before running the React Native application, install the dependencies by running `yarn install` or `npm install` in the `react-native` directory.
### Web View (Recommended - Quickest Method)
The quickest way to test the application is by using the web view. While testing on a physical device is also supported, we recommend using [local HTTPS development](https://docs.expo.dev/guides/local-https-development/) as it requires fewer backend modifications.
@ -69,28 +67,21 @@ The quickest way to test the application is by using the web view. While testing
Follow these steps to set up the web view:
1. Navigate to the `react-native` directory and start the application by running:
```bash
```bash
yarn web
```
```
2. Generate SSL certificates by running the following command in a separate directory:
```bash
```bash
mkcert localhost
```
```
3. Set up the local proxy by running:
```bash
```bash
yarn create:local-proxy
```
```
The default port is `443`. To use a different port, specify the `SOURCE_PORT` environment variable:
```bash
SOURCE_PORT=8443 yarn create:local-proxy
```
4. If you changed the port in the previous step, update the `apiUrl` in `Environment.ts` accordingly.
5. Update the mobile application settings in the database and re-run the migrations. If you specified a custom port, ensure the port is updated in the configuration as well:
```json
```json
"OpenIddict": {
"Applications": {
"MyApplication_Mobile": {
@ -99,7 +90,7 @@ Follow these steps to set up the web view:
}
}
}
```
```
### Running on Emulator/Simulator
@ -111,17 +102,17 @@ If you prefer to test on an Android emulator or iOS simulator, you'll need to co
{{ if Architecture == "Monolith" }}
![react native monolith environment local IP](../../../images/react-native-monolith-environment-local-ip.png)
react native monolith environment local IP
{{ else if Architecture == "Tiered" }}
![react native tiered environment local IP](../../../images/react-native-tiered-environment-local-ip.png)
react native tiered environment local IP
> Make sure that `issuer` matches the running address of the `.AuthServer` project, `apiUrl` matches the running address of the `.HttpApi.Host` or `.Web` project.
{{ else }}
![react native microservice environment local IP](../../../images/react-native-environment-local-ip.png)
react native microservice environment local IP
> Make sure that `issuer` matches the running address of the `.AuthServer` project, `apiUrl` matches the running address of the `.AuthServer` project.
@ -131,22 +122,22 @@ If you prefer to test on an Android emulator or iOS simulator, you'll need to co
> The React Native application was generated with [Expo](https://expo.io/). Expo is a set of tools built around React Native to help you quickly start an app, and it includes many features.
![expo-cli-options](../../../images/rn-options.png)
expo-cli-options
In the image above, you can start the application on an Android emulator, an iOS simulator, or a physical phone by scanning the QR code with the [Expo Client](https://expo.io/tools#client) or by choosing the corresponding option.
### Expo
![React Native login screen on iPhone 16](../../../images/rn-login-iphone.png)
React Native login screen on iPhone 16
### Android Studio
1. Start the emulator in **Android Studio** before running the `yarn start` or `npm start` command.
2. Press **a** to open in Android Studio.
![React Native login screen on Android Device](../../../images/rn-login-android-studio.png)
React Native login screen on Android Device
Enter **admin** as the username and **1q2w3E\*** as the password to log in to the application.
Enter **admin** as the username and **1q2w3E** as the password to log in to the application.
The application is up and running. You can continue to develop your application based on this startup template.
@ -172,11 +163,10 @@ A React Native application running on an Android emulator or a physical phone **
{{ if Architecture == "Monolith" }}
![React Native monolith host project configuration](../../../images/react-native-monolith-be-config.png)
React Native monolith host project configuration
- Open the `appsettings.json` file in the `.DbMigrator` folder. Replace the `localhost` address in the `RootUrl` property with your local IP address. Then, run the database migrator.
- Open the `appsettings.Development.json` file in the `.HttpApi.Host` folder. Add this configuration to accept global requests for testing the React Native application in the development environment.
```json
{
"Kestrel": {
@ -191,11 +181,10 @@ A React Native application running on an Android emulator or a physical phone **
{{ else if Architecture == "Tiered" }}
![React Native tiered project configuration](../../../images/react-native-tiered-be-config.png)
React Native tiered project configuration
- Open the `appsettings.json` file in the `.DbMigrator` folder. Replace the `localhost` address in the `RootUrl` property with your local IP address. Then, run the database migrator.
- Open the `appsettings.Development.json` file in the `.AuthServer` folder. Add this configuration to accept global requests for testing the React Native application in the development environment.
```json
{
"Kestrel": {
@ -207,9 +196,7 @@ A React Native application running on an Android emulator or a physical phone **
}
}
```
- Open the `appsettings.Development.json` file in the `.HttpApi.Host` folder. Add this configuration to accept global requests. Additionally, you need to configure the authentication server as mentioned above.
```json
{
"Kestrel": {
@ -230,10 +217,9 @@ A React Native application running on an Android emulator or a physical phone **
{{ else if Architecture == "Microservice" }}
![React Native microservice project configuration](../../../images/react-native-microservice-be-config.png)
React Native microservice project configuration
- Open the `appsettings.Development.json` file in the `.AuthServer` folder. Add this configuration to accept global requests for testing the React Native application in the development environment.
```json
{
"App": {
@ -248,9 +234,7 @@ A React Native application running on an Android emulator or a physical phone **
}
}
```
- Open the `appsettings.Development.json` file in the `.AdministrationService` folder. Add this configuration to accept global requests for testing the React Native application in the development environment. You should also provide the authentication server configuration. Additionally, you need to apply the same process for all services you will use in the React Native application.
```json
{
"App": {
@ -271,9 +255,7 @@ A React Native application running on an Android emulator or a physical phone **
}
}
```
- Update the `appsettings.json` file in the `.IdentityService` folder. Replace the `localhost` configuration with your local IP address for the React Native application.
```json
{
//...
@ -292,9 +274,7 @@ A React Native application running on an Android emulator or a physical phone **
}
}
```
- Finally, update the mobile gateway configurations as follows:
```json
//gateways/mobile/MyMicroserviceProject.MobileGateway/Properties/launchSettings.json
{
@ -319,7 +299,6 @@ A React Native application running on an Android emulator or a physical phone **
}
}
```
```json
//gateways/mobile/MyMicroserviceProject.MobileGateway/appsettings.json
{
@ -367,7 +346,6 @@ A React Native application running on an Android emulator or a physical phone **
}
}
```
{{ end }}
Run the backend application(s) as described in the [getting started document](../../../get-started).
Run the backend application(s) as described in the [getting started document](../../../get-started).

439
docs/en/framework/ui/react/index.md

@ -0,0 +1,439 @@
```json
//[doc-seo]
{
"Description": "Learn how to build modern web applications with ABP using React UI — a React-first approach with a dedicated Admin Console, built on Vite, shadcn/ui, Zod, and Axios."
}
```
# React UI
## Introduction
ABP provides a **React UI** option for building modern, client-side web applications. The React UI is part of the **modern template system** and is only available when creating a solution with the `--modern` flag via the [ABP CLI](../../../cli/index.md) or through the **Modern Wizard** in [ABP Studio](../../../studio/index.md).
> React UI is **not** available in the legacy (non-modern) templates. You must use the modern template system to get a React-based solution. See [Creating a Solution](#creating-a-solution) below.
The React UI is built on a modern, industry-standard stack:
| Technology | Purpose |
|---|---|
| [Vite](https://vitejs.dev/) | Build tool and dev server |
| [React](https://react.dev/) | UI framework |
| [shadcn/ui](https://ui.shadcn.com/) | Component library (built on Radix UI + Tailwind CSS) |
| [Zod](https://zod.dev/) | Schema validation |
| [Axios](https://axios-http.com/) | HTTP client |
| [Vitest](https://vitest.dev/) | Unit testing |
| [React Router](https://reactrouter.com/) | Client-side routing |
| [OpenID Connect / OIDC](https://openid.net/connect/) | Authentication (via the ABP Auth Server) |
## React App and Admin Console
Every modern React solution consists of two parts: **your React application** and the **ABP Admin Console**.
### React App (Your Application)
This is **your application** — the user-facing SPA that you own and customize freely. It comes with:
- A sample **Books CRUD page** (when `--sample-crud-page` is used) demonstrating how to build a full create/read/update/delete page with the ABP backend
- A plain **Users page** as a minimal reference
- Pre-configured authentication via OIDC against the ABP Auth Server
- Pre-configured HTTP client (Axios) with ABP API integration
This is where you build your business-specific pages and features.
The location of the React app differs by template type:
- **Layered (`app --modern`) and Single-layer (`app-nolayers --modern`)**: the React app lives at the **root of the solution** (alongside the backend projects).
- **Microservice (`microservice --modern`)**: the React app lives at `apps/react/`.
### React Admin Console (`Volo.Abp.AdminConsole`)
The **ABP Admin Console** is a pre-built React application that provides all standard ABP module management pages. It is delivered via the `Volo.Abp.AdminConsole` NuGet package and requires no modification on your part — it is updated automatically when you update your ABP packages.
The Admin Console includes pages for:
- Users & Roles management
- Organization Units
- Settings
- Audit Logs
- OpenIddict (Application, Scope management)
- Language Management *(if included)*
- Text Template Management *(if included)*
- GDPR *(if included)*
- SaaS / Tenant Management *(if included)*
- And all other optional module pages based on your solution configuration
How the Admin Console is hosted also differs by template type:
- **Layered and Single-layer templates**: The `Volo.Abp.AdminConsole` package is added directly to your `*.HttpApi.Host` project. It serves the Admin Console React app at the `/admin-console/*` path of your backend (e.g., `https://localhost:44300/admin-console/`). There is no separate `apps/react-admin-console/` folder — the Admin Console UI is embedded in and served by the backend.
- **Microservice template**: The Admin Console runs as a standalone React app at `apps/react-admin-console/`, served through the Web Gateway (YARP) alongside the main React app.
In both cases the Admin Console is accessible from the main React app via a navigation link.
## Creating a Solution
### Using ABP CLI
Pass the `--modern` flag to `abp new`:
````bash
# Layered app with React UI (default when --modern is used)
abp new Acme.BookStore --template app --modern
# Single-layer app with React UI
abp new Acme.BookStore --template app-nolayers --modern
# Microservice solution with React UI + React Admin Console
abp new Acme.BookStore --template microservice --modern
````
The `react` UI framework is the default when `--modern` is specified. You can also pass it explicitly:
````bash
abp new Acme.BookStore --template app --modern --ui-framework react
````
To create a solution without any UI (API-only backend):
````bash
abp new Acme.BookStore --template app --modern --ui-framework no-ui
````
See the [ABP CLI documentation](../../../cli/index.md#modern-templates) for the full list of options.
### Using ABP Studio
Open ABP Studio and use the **New Solution** wizard. Select the **Modern** template variant and choose **React** as the UI framework. The wizard guides you through all available options and generates the solution.
## Solution Structure
The layout of the React-related files depends on the template type.
### Layered and Single-layer Templates
For `app --modern` and `app-nolayers --modern`, the React app lives at the root of the solution alongside the backend projects. The Admin Console is embedded in the backend via the `Volo.Abp.AdminConsole` NuGet package — there is no separate React Admin Console folder.
```
Acme.BookStore/
├── react/ # Your React application
│ ├── src/
│ │ ├── pages/ # Your page components
│ │ │ ├── books/ # Sample Books CRUD page
│ │ │ └── users/ # Sample Users page
│ │ ├── components/ # Shared UI components
│ │ ├── lib/ # Utilities, API clients
│ │ ├── hooks/ # Custom React hooks
│ │ └── main.tsx # Entry point
│ ├── public/
│ │ └── dynamic-env.json # Runtime configuration
│ ├── package.json
│ └── vite.config.ts
├── src/
│ ├── Acme.BookStore.Application/
│ ├── Acme.BookStore.Domain/
│ ├── Acme.BookStore.EntityFrameworkCore/
│ └── Acme.BookStore.HttpApi.Host/ # Hosts Admin Console at /admin-console/*
└── ...
```
### Microservice Template
For `microservice --modern`, both the React app and the React Admin Console are standalone apps under the `apps/` directory, each served through the Web Gateway (YARP).
```
Acme.BookStore/
├── apps/
│ ├── react/ # Your React application
│ │ ├── src/
│ │ │ ├── pages/
│ │ │ ├── components/
│ │ │ ├── lib/
│ │ │ ├── hooks/
│ │ │ └── main.tsx
│ │ ├── public/
│ │ │ └── dynamic-env.json # Runtime configuration
│ │ ├── package.json
│ │ └── vite.config.ts
│ ├── react-admin-console/ # ABP Admin Console (managed by ABP)
│ │ ├── public/
│ │ │ └── dynamic-env.json
│ │ └── ...
│ └── auth-server/ # OpenIddict Auth Server
├── gateways/
│ └── web/ # YARP reverse proxy for React apps
├── services/
│ ├── identity/
│ ├── administration/
│ └── ...
└── ...
```
## Configuration
### Runtime Configuration (`dynamic-env.json`)
The React app reads its runtime configuration from `public/dynamic-env.json`. This file is loaded at startup and allows you to change settings without rebuilding the application — useful for different environments (development, staging, production).
```json
{
"oAuthConfig": {
"issuer": "https://localhost:44301/",
"clientId": "Acme.BookStore_App",
"scope": "openid profile email offline_access BookStore"
},
"apis": {
"default": {
"url": "https://localhost:44300",
"rootNamespace": "Acme.BookStore"
}
}
}
```
| Key | Description |
|---|---|
| `oAuthConfig.issuer` | URL of the OpenIddict Auth Server |
| `oAuthConfig.clientId` | The OpenIddict client ID registered for this app |
| `oAuthConfig.scope` | OAuth scopes to request |
| `apis.default.url` | Base URL of the backend API |
| `apis.default.rootNamespace` | Root namespace used for API proxy generation |
For the **microservice** modern template, the `apis.default.url` points to the **Web Gateway** (YARP reverse proxy) instead of a single backend host.
### Admin Console Configuration
For the **microservice** template, the Admin Console has its own `dynamic-env.json` (at `apps/react-admin-console/public/dynamic-env.json`) and uses a separate OpenIddict client (`<ProjectName>_AdminConsole`).
For **layered and single-layer** templates, the Admin Console is embedded in the backend via the `Volo.Abp.AdminConsole` package and does not have a separate configuration file — it inherits its settings from the backend host.
## Authentication
Both the React app and the Admin Console authenticate using **OpenID Connect (OIDC)** against the ABP Auth Server (OpenIddict). The auth flow is handled transparently — when a user visits a protected page, they are redirected to the Auth Server login page and returned to the app after successful authentication. All clients use the **Authorization Code flow with PKCE**, which is the recommended flow for SPAs.
The number of seeded OpenIddict clients depends on the template:
- **Layered and Single-layer templates**: one client is seeded — `<ProjectName>_App` for the React SPA. The Admin Console is embedded in the backend and shares the same authentication context.
- **Microservice template**: two clients are seeded — `<ProjectName>_App` for the main React SPA and `<ProjectName>_AdminConsole` for the standalone React Admin Console app.
## Making API Calls
The React app uses **Axios** as the HTTP client, pre-configured with:
- The base URL from `dynamic-env.json`
- Automatic Bearer token injection from the OIDC session
- ABP-compatible error handling (reads `error.data` from ABP error responses)
**Example: Fetching a list of books**
```typescript
import { useQuery } from '@tanstack/react-query';
import { apiClient } from '@/lib/api-client';
interface BookDto {
id: string;
name: string;
type: number;
publishDate: string;
price: number;
}
interface PagedResult<T> {
items: T[];
totalCount: number;
}
export function useBooks() {
return useQuery({
queryKey: ['books'],
queryFn: () =>
apiClient
.get<PagedResult<BookDto>>('/api/app/book')
.then((res) => res.data),
});
}
```
## Localization
The React app integrates with ABP's [localization system](../../../framework/fundamentals/localization.md). Localization resources are fetched from the backend at startup via the `/api/abp/application-configuration` endpoint and made available throughout the app.
**Example: Using localization in a component**
```typescript
import { useLocalization } from '@/hooks/use-localization';
export function MyComponent() {
const { l } = useLocalization('BookStore');
return <h1>{l('Books')}</h1>;
}
```
The `l(key)` function looks up the key in the loaded localization resources for the given resource name (`'BookStore'` in this example).
## Authorization
Permission checks are available via a hook that reads the current user's granted permissions from the ABP application configuration:
```typescript
import { usePermissions } from '@/hooks/use-permissions';
export function BooksPage() {
const { isGranted } = usePermissions();
return (
<div>
{isGranted('BookStore.Books.Create') && (
<button>Create Book</button>
)}
</div>
);
}
```
Permissions are defined on the server side using ABP's [permission system](../../../framework/fundamentals/authorization/index.md) and are automatically available in the React app.
## Tech Stack Details
### shadcn/ui Components
The React app uses [shadcn/ui](https://ui.shadcn.com/) as the component library. shadcn/ui is not a traditional npm package — components are copied directly into your project under `src/components/ui/`, giving you full ownership and the ability to customize them freely.
Common components available out of the box include: `Button`, `Input`, `Table`, `Dialog`, `Form`, `Select`, `Tabs`, `Card`, `Badge`, `Dropdown Menu`, and more.
### Form Validation with Zod
Forms use [Zod](https://zod.dev/) schemas for validation, integrated with [React Hook Form](https://react-hook-form.com/):
```typescript
import { z } from 'zod';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
const createBookSchema = z.object({
name: z.string().min(1).max(128),
price: z.number().min(0),
publishDate: z.string(),
});
type CreateBookInput = z.infer<typeof createBookSchema>;
export function CreateBookForm() {
const form = useForm<CreateBookInput>({
resolver: zodResolver(createBookSchema),
});
// ...
}
```
### Testing with Vitest
The React app is pre-configured with [Vitest](https://vitest.dev/) for unit testing:
```bash
# Run tests
npm run test
# Run tests with coverage
npm run test:coverage
```
## Running the Application
### Development
1. Start the backend (from ABP Studio or `dotnet run` in the `*.HttpApi.Host` project).
2. Navigate to the React app directory and start the dev server.
For **layered and single-layer** templates, the React app is at the solution root:
````bash
cd react
npm install
npm run dev
````
For the **microservice** template, it is under `apps/`:
````bash
cd apps/react
npm install
npm run dev
````
The app will be available at `https://localhost:3000` (or the port configured in `vite.config.ts`).
3. Access the Admin Console:
- **Layered / Single-layer**: navigate to the backend URL + `/admin-console/` (e.g., `https://localhost:44300/admin-console/`).
- **Microservice**: navigate to the Web Gateway URL + `/admin-console/`.
### Production Build
````bash
# Layered / Single-layer
cd react && npm run build
# Microservice
cd apps/react && npm run build
````
The output is placed in `dist/` and can be served by any static file host or CDN.
## Accessing the Admin Console
The Admin Console is accessible from within the main React app. After logging in, you will find a link to the Admin Console in the navigation. Clicking it opens the Admin Console, which is served by the backend at `/admin-console/*`.
The Admin Console provides full management capabilities for:
- **Identity**: Users, Roles, Claims, Organization Units
- **OpenIddict**: Applications, Scopes
- **Settings**: Application-wide and tenant-level settings
- **Audit Logs**: View and filter audit log entries
- **Language Management** *(optional)*
- **Text Template Management** *(optional)*
- **GDPR** *(optional)*
- **SaaS / Tenant Management** *(optional)*
- **And more**, depending on the modules included in your solution
## Customization
### Adding New Pages
Create a new file under `src/pages/` and register the route in the router configuration:
```typescript
// src/router.tsx (or similar)
import { BooksPage } from './pages/books/books-page';
import { MyNewPage } from './pages/my-feature/my-new-page';
const routes = [
{ path: '/books', element: <BooksPage /> },
{ path: '/my-feature', element: <MyNewPage /> },
// ...
];
```
### Adding Menu Items
Add entries to the navigation configuration to include your new pages in the sidebar or top navigation:
```typescript
// src/config/navigation.ts (or similar)
export const navigationItems = [
{ label: 'Books', path: '/books', icon: BookIcon },
{ label: 'My Feature', path: '/my-feature', icon: StarIcon },
];
```
### Customizing shadcn/ui Components
Since shadcn/ui components live in `src/components/ui/`, you can modify them directly. For example, to change the default button variant or add a new variant, edit `src/components/ui/button.tsx`.
## See Also
- [ABP CLI — Modern Templates](../../../cli/index.md#modern-templates)
- [ABP Studio](../../../studio/index.md)
- [Localization](../../../framework/fundamentals/localization.md)
- [Authorization / Permissions](../../../framework/fundamentals/authorization/index.md)
- [Auto API Controllers](../../../framework/api-development/auto-controllers.md)
Loading…
Cancel
Save