根据不基于哈希值的路径定义路由 [英] Define a route based on the path not on the hash value
本文介绍了根据不基于哈希值的路径定义路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Aurelia路由器将路径映射到hash
.
The Aurelia router maps a route the the hash
.
http://subdomain.hostname.tld/pathA/pathB/pathC?queryKey = queryValue#hash
我们如何根据pathA/pathB/pathC
值定义Aurelia路线?
How can we define an Aurelia route based on the pathA/pathB/pathC
value instead?
推荐答案
这是文档中的一个示例.但是,为了使#hash正常工作,您需要将config.options.hashChange指定为false:
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;
这篇关于根据不基于哈希值的路径定义路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文