本文介绍了如何从Aurelia中的URL中删除#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以逐步解释,我们如何从奥雷利亚(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.

  1. 向其中添加基本标记 HTML文档的标题. 我认为这不是必需的步骤,因为我的应用程序无需使用它.

  1. 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([
                //... 
            ]);
        }
    }
  1. 配置服务器以支持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中删除#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 10:01