Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aurelia not loading URLs without hash

I have read the other questions on this issue and the answers didn't seem to help me. Maybe because I'm using ASP CORE. If I navigate to http://localhost:5000/#home the routing works fine. But when I remove the hashtag, the page does not load. Here is my routing code:

import {Redirect, NavigationInstruction, RouterConfiguration} from 'aurelia-router';

export class App {
  configureRouter(config: RouterConfiguration): void {
    config.title = 'xxxx';
    config.options.hashChange = false;
    config.options.root = '/';
    config.map([
      { route: ['home'], name: 'home', moduleId: 'views/home' },
      { route: '', redirect: 'home'}
    ]);
  }
}

I've also tried adding this:

config.options.pushState = true;
config.options.hashChange = true;
like image 208
Dwayne Love Avatar asked Dec 21 '25 11:12

Dwayne Love


1 Answers

If you are using asp.net core you need to setup server side routing to redirect your requests to index.html. In your Startup.cs in the Configure method you need to do something like this:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        app.Use(async (context, next) =>
        {
            await next();

            if (context.Response.StatusCode == 404
                && !Path.HasExtension(context.Request.Path.Value))
            {
                context.Request.Path = "/index.html";
                await next();
            }
        });

        app.UseStaticFiles();
    }
like image 150
Simon Farrugia Avatar answered Dec 23 '25 00:12

Simon Farrugia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!