如何从 Aurelia 中的 URL 中删除 # [英] How to remove # from URL in Aurelia
问题描述
谁能一步一步解释一下,我们如何从Aurelia的URL中删除#
Can anybody please explain in step by step manner, how can we remove # from URL in Aurelia
推荐答案
您正在寻找的功能称为 PushState.您可以在备忘单 Aurelia Hub 的一部分.只需向下滚动到 Routing
/Configuring PushState
.
The feature you are looking for is called PushState. You can find more info in Cheat Sheet section of Aurelia Hub. Just scroll down to Routing
/ Configuring PushState
.
添加基本标签HTML 文档的头部.我认为这不是必需的步骤,因为我的应用程序在没有它的情况下也能运行.
Add a base tag to the head of your HTML document. I don't think this is a required step, since my apps are working without it.
如果您使用的是 JSPM,请配置 baseURL
(在 config.js
文件中).
If you are using JSPM, configure baseURL
(in config.js
file).
在路由器配置中启用 PushState:
Enable PushState in router config:
export class App {
configureRouter(config) {
config.title = 'Aurelia';
config.options.pushState = true; // <-- this line
config.map([
//...
]);
}
}
配置服务器以支持 PushState.基本上,这意味着您的服务器应该将所有未知路由/URL 重定向到主 URL(您的 Aurelia 应用程序的地址 -
index.html
,/home/index
...)
此步骤取决于您使用的服务器端技术.IE.对于 ASP.NET MVC,这是您定义路由配置的方式:
This step depends on the server-side technology you are using. I.e. for ASP.NET MVC, this is how you would define your route config:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
// url: "{*pathinfo}" - this redirects all server side calls
// to Home/Index (default route)
// with this single change, HTML5 push state is enabled
routes.MapRoute(
name: "Default",
url: "{*pathinfo}",
defaults: new {
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
}
}
Dwayne Charrington 在他的 Discover 上有一篇关于 PushState 的好文章Aurelia 站点,他解释了如何在各种服务器端框架(如 Apache、Nginx、.NET Core 和 Node.js Express)上配置 PushState.
Dwayne Charrington has a nice article about PushState on his Discover Aurelia site, where he explains how to configure PushState on various server-side frameworks, like Apache, Nginx, .NET Core and Node.js Express.
这篇关于如何从 Aurelia 中的 URL 中删除 #的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!