【问题标题】:Define a route based on the path not on the hash value根据路径而不是哈希值定义路由
【发布时间】:2016-07-30 06:09:16
【问题描述】:

Aurelia 路由器映射hash 的路由。

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

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

【问题讨论】:

    标签: aurelia


    【解决方案1】:

    这是文档中的一个示例。但是为了使#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' }
        ]);
      }
    }
    

    你的目的的重要行是以下两行:

    // switch from hash (#) to slash (/) navigation
    config.options.root = "/";
    config.options.hashChange = false;
    

    【讨论】:

      【解决方案2】:

      您可以设置推送状态。这在我们的文档中进行了讨论:http://aurelia.io/hub.html#/doc/article/aurelia/router/latest/router-configuration/2

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-04-05
        • 1970-01-01
        • 2020-05-19
        • 2019-02-13
        • 1970-01-01
        • 1970-01-01
        • 2017-09-11
        相关资源
        最近更新 更多