根据路径而不是哈希值定义路由

Sha*_*tin 1 aurelia

Aurelia 路由器映射一条路由hash

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

我们如何根据pathA/pathB/pathC值定义 Aurelia 路线?

Jer*_*lez 5

这是文档中的示例。但为了让 #hash 工作,你需要将 config.options.hashChange 指定为 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' }
    ]);
  }
}
Run Code Online (Sandbox Code Playgroud)

对于您的目的来说,重要的几行是以下两行:

// switch from hash (#) to slash (/) navigation
config.options.root = "/";
config.options.hashChange = false;
Run Code Online (Sandbox Code Playgroud)