Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Asp.net Core 2 Razor Pages MapSpaFallback suggestion #1354

Closed

Description

@pholly

MapSpaFallback works well for MVC routes but does not exist for the new Razor Pages.

If SpaRouteConstraint were public instead of internal with a little work developers can add the constraint to Razor pages:

//Starup.cs ConfigureServices
//thank you Scott Hanselman https://www.hanselman.com/blog/AddingACustomInlineRouteConstraintInASPNETCore10.aspx
services.Configure<RouteOptions>(options => 
                options.ConstraintMap.Add("spaRoute", typeof(SpaRouteConstraint)));
services.AddMvc()
                .AddRazorPagesOptions(options =>
                {
                    options.Conventions.AddPageRoute("/Index", "{*catchAll:spaRoute(catchAll)}");
                });

Would be even better if JavaScriptServices somehow added SpaRouteConstraint to the ConstraintMap.

For now I'll just copy the SpaRouteConstraint class.
Thanks,
Philip

Activity

  1. buvinghausen commented on Oct 25, 2017

    @buvinghausen

    I have just been using a regex to exclude the api routes.....

    services
        .AddMvc()
        .AddRazorPagesOptions(options =>
        {
            options.Conventions.AddPageRoute("/Index", "{*url:regex(^(?!api).*$)}");
        });
  2. SteveSandersonMS commented on Oct 26, 2017

    @SteveSandersonMS
    Member

    Thanks for the suggestion. In the next update, we're providing an alternative to MapSpaFallbackRoute that isn't coupled to the concept of MVC actions. It looks like this:

    app.UseSpa("root-directory-goes-here", () => { /* config goes here */ });
    

    This is generic middleware that you can use either with MVC or Razor projects. Hopefully that will cover your requirements even more cleanly.

  3. RichiCoder1 commented on Oct 27, 2017

    @RichiCoder1

    @SteveSandersonMS That'd be awesome. On at least two of my projects, there's just a thin layer of razor over an index.html (generated by webpack).

  4. StefanKern commented on Feb 17, 2018

    @StefanKern

    @buvinghausen thank you for your solution. I took me a long time to understand it but it works now.

    @SteveSanderson: when is this app.UseSpa avalible. With the newset version of .Net Core I don't have it yet :(

  5. jjgriff93 commented on Oct 13, 2018

    @jjgriff93

    @SteveSandersonMS also facing this issue still - is this an update we can expect soon?

  6. SteveSandersonMS commented on Oct 15, 2018

    @SteveSandersonMS
    Member

    @jjgriff93 We shipped UseSpa in ASP.NET Core 2.1.

  7. jjgriff93 commented on Oct 16, 2018

    @jjgriff93

    Thanks @SteveSandersonMS - turns out it was a completely unrelated problem to spaservices! It was an SSL error. @jfborie I'm probably not best placed to help as I'm fairly new with the framework myself; however if you post your issue up separately and reference it I'm happy to take a look and see if i have any suggestions. Make sure you tell us what the error is with any code you can share

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy