dotnet / dotnet/maui

Shell Routing through attributes on page (using source generators)

Open
#5,312 10 comments 6 reactions 0 assignees View on GitHub
area-controls-shell proposal/open
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 14h
Merged PRs (30d)
296

Description

### Description

Today, we must register each page in the AppShell on startup such as:

```csharp
public AppShell()
{
InitializeComponent();

Routing.RegisterRoute(nameof(DetailsPage), typeof(DetailsPage));
}
```

However, it would be nicer to align with how ASP.NET Core routing works and make it an attribute on the page. Since this would require assembly scanning today, this should be implemented as source generators for optimal performance.

### (Public) API Changes

```csharp
[Route(nameof(DetailsPage))]
public partial class DetailsPage : ContentPage

{

}
```

This would generate code necessary to register the `DetailsPage` with the route of `DetailsPage`.

### Usage Scenarios

See above :)

### Backward Compatibility

Would be an added option and an upgrade from the existing mechanism.

### Difficulty

Medium

Contributor guide

Open the contributing guide

Research direction

Start with the AppShell startup example and the existing Routing.RegisterRoute call shown in the issue. Then investigate the proposed Route attribute and source-generator integration, including how DetailsPage would be discovered. Done means the attribute-based registration works while the existing mechanism remains available.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop-dev, mobile-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.