Hello,
I am currently working on my first project with elm-spa (ryannhg/elm-spa: 6.0.0).
When I refresh my dynamic Page, I get a 404 Error but the route is looking correctly. Now when I open the Page from a Button click from my Homepage, the dynamic Page shows properly.
Can somebody explain me how I can redirect the route to the Page when I am refreshing?
How do you host the app? Is the host catching all the subroutes correctly (basically it should ignore the route and just render/display the elm-app again)
I am using the app only local right now.
I’ve just created a Homepage like in the elm-spa guide and created a dynamic route “class/(Dynamic)name” which I can reach from my Homepage.
For the Back-End I am using asp.net MVC.
For me it looks like the route is looking correctly. (But I am still pretty unexperienced, so…)
For ASP.NET I usually use either ~MapSpaFallbackRoute~ or a Route-Attribute with a {*url} catch-all on Home-Index.
You can find out if this is the issue by inspecting the source of the page in your browser - I suspect that the 404 is from your backend and that you don’t get any meaningful HTML containing the elm-start-code back.
Sorry turns out that for newer versions it’s MapFallbackToController - this is an example that works for me:
app.UseEndpoints(endpoints =>
{
// default - you can stick with this if you want an error page or some other non-elm related controller/view
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
// map everything else to Home/Index (works for routes handled with elm-spa
endpoints.MapFallbackToController("Index", "Home");
});
The MapFallbackToController works perfectly and your assumption with the empty source was correct aswell.
Thanks for your fast help!