Skip to content

Improvements to Page Api for navigation #21984

Description

@emmauss

Is your feature request related to a problem? Please describe.

Current Page api for navigation is limited requiring the host to instantiate the page before passing it to the INavigation instance. Services that want to detach themselves from views have to use factories as middlemen to create page instances to navigate to.

Describe the solution you'd like

Add the following api to INavigation

Task PushAsync(Page page, IPageTransition? transition, object? parameter);

Task ReplaceAsync(Page page, IPageTransition? transition, object? parameter);

Task PushModalAsync(Page page, IPageTransition? transition, object? parameter);

NavigatingFromEventArgs, NavigatingToEventArgs, NavigatedFromEventArgs, NavigatedToEventArgs, NavigationEventArgs`

public object? Parameter { get; }
public static class PageNavigationExtensions
{
    extension(INavigation navigation)
    {
        /// <summary>
        /// Pushes a new page of type <typeparamref name="T"/> onto the navigation stack, using <paramref name="transition"/> with optional <paramref name="parameter"/>.
        /// </summary>
        public Task PushAsync<T>(IPageTransition? transition = null, object? parameter = null) where T : Page, new();

        /// <summary>
        /// Replaces the current top page with a new page of type <typeparamref name="T"/>, using <paramref name="transition"/> with optional <paramref name="parameter"/>.
        /// </summary>
        public Task ReplaceAsync<T>(IPageTransition? transition = null, object? parameter = null) where T : Page, new();

        /// <summary>
        /// Pushes a new modal page of type <typeparamref name="T"/> onto the modal stack, using <paramref name="transition"/> with optional <paramref name="parameter"/>.
        /// </summary>
        public Task PushModalAsync<T>(IPageTransition? transition = null, object? parameter = null) where T : Page, new();
    }
}

The parameter value is set in the Navigating args and is read by the page on navigating to or from.

Describe alternatives you've considered

No response

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions