Define a route based on the path not on the hash v

2019-06-03 17:44发布

The Aurelia router maps a route the the hash.

http://subdomain.hostname.tld/pathA/pathB/pathC?queryKey=queryValue#hash

How can we define an Aurelia route based on the pathA/pathB/pathC value instead?

2条回答
男人必须洒脱
2楼-- · 2019-06-03 18:38

Here's an example from the docs. But in order the #hash to work you'll need to specify config.options.hashChange as false:

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

export class App {
  configureRouter(config: RouterConfiguration): void {
    config.title = 'Aurelia';
    config.options.pushState = true;

    config.options.root = '/';
    config.options.hashChange = false;

    config.map([
      { route: ['welcome'],    name: 'welcome',     moduleId: 'welcome',      nav: true, title:'Welcome' },
      { route: 'flickr',       name: 'flickr',      moduleId: 'flickr',       nav: true, auth: true },
      { route: 'child-router', name: 'childRouter', moduleId: 'child-router', nav: true, title:'Child Router' },
      { route: '',             redirect: 'welcome' }
    ]);
  }
}

The important lines for your purpose are these two:

// switch from hash (#) to slash (/) navigation
config.options.root = "/";
config.options.hashChange = false;
查看更多
Viruses.
3楼-- · 2019-06-03 18:45

You can set up Push State. This is discussed in our docs here: http://aurelia.io/hub.html#/doc/article/aurelia/router/latest/router-configuration/2

查看更多
登录 后发表回答