Skip to content
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
pholly opened this issue Oct 25, 2017 · 9 comments
Closed

Asp.net Core 2 Razor Pages MapSpaFallback suggestion #1354

pholly opened this issue Oct 25, 2017 · 9 comments

Comments

@pholly
Copy link

pholly commented Oct 25, 2017

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

@buvinghausen
Copy link

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

services
    .AddMvc()
    .AddRazorPagesOptions(options =>
    {
        options.Conventions.AddPageRoute("/Index", "{*url:regex(^(?!api).*$)}");
    });

@SteveSandersonMS
Copy link
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.

@RichiCoder1
Copy link

@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).

@StefanKern
Copy link

@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 :(

@jjgriff93
Copy link

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

@SteveSandersonMS
Copy link
Member

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

@ghost
Copy link

ghost commented Oct 15, 2018

Hi , @jjgriff93
I am testing https://github.com/vasyliv/angular6/tree/angular-server to include it my project. I cannot get spa fall back to work any suggestion?

@jjgriff93
Copy link

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

@ghost
Copy link

ghost commented Oct 16, 2018

I hit too many snag i am trying with https://github.com/angular/universal-starter for now. Thx.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants