如何从 Aurelia 中的 URL 中删除 #
How to remove # from URL in Aurelia
任何人都可以逐步解释,我们如何从 Aurelia
中的 URL 中删除 #
您要查找的功能称为 Aurelia Hub 的 PushState. You can find more info in Cheat Sheet 部分。只需向下滚动到 Routing
/ Configuring PushState
.
将 a base tag 添加到 HTML 文档的开头。 我认为这不是必需的步骤,因为我的应用程序没有它也能正常工作。
如果您使用的是 JSPM,请配置 baseURL
(在 config.js
文件中)。
在路由器配置中启用 PushState:
export class App {
configureRouter(config) {
config.title = 'Aurelia';
config.options.pushState = true; // <-- this line
config.map([
//...
]);
}
}
配置服务器以支持 PushState。基本上,这意味着您的服务器应该将所有未知 routes/URLs 重定向到主页 URL(您的 Aurelia 应用程序的地址 - index.html
、/home/index
...)。
此步骤取决于您使用的服务器端技术。 IE。对于 ASP.NET MVC,这是定义路由配置的方式:
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 a nice article about PushState 在他的 Discover Aurelia 站点上,他解释了如何在各种服务器端框架上配置 PushState,例如 Apache、Nginx、.NET Core 和 Node.js Express .
如果您正在寻找一种快速使其工作的方法,请执行以下操作:
在 src/app.ts
中的路由器配置中:
config.options.pushState = true;
在根目录的index.html中添加如下内容:
<base href="/">
任何人都可以逐步解释,我们如何从 Aurelia
中的 URL 中删除 #您要查找的功能称为 Aurelia Hub 的 PushState. You can find more info in Cheat Sheet 部分。只需向下滚动到 Routing
/ Configuring PushState
.
将 a base tag 添加到 HTML 文档的开头。 我认为这不是必需的步骤,因为我的应用程序没有它也能正常工作。
如果您使用的是 JSPM,请配置
baseURL
(在config.js
文件中)。在路由器配置中启用 PushState:
export class App {
configureRouter(config) {
config.title = 'Aurelia';
config.options.pushState = true; // <-- this line
config.map([
//...
]);
}
}
配置服务器以支持 PushState。基本上,这意味着您的服务器应该将所有未知 routes/URLs 重定向到主页 URL(您的 Aurelia 应用程序的地址 -
index.html
、/home/index
...)。此步骤取决于您使用的服务器端技术。 IE。对于 ASP.NET MVC,这是定义路由配置的方式:
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 a nice article about PushState 在他的 Discover Aurelia 站点上,他解释了如何在各种服务器端框架上配置 PushState,例如 Apache、Nginx、.NET Core 和 Node.js Express .
如果您正在寻找一种快速使其工作的方法,请执行以下操作:
在
src/app.ts
中的路由器配置中:config.options.pushState = true;
在根目录的index.html中添加如下内容:
<base href="/">