角JavaScript的清洁网址 [英] angular javascript cleaning URL

查看:104
本文介绍了角JavaScript的清洁网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用AngularJS一个温泉开发的应用程序。访问应用程序可以发生在两个方面:

I have a SPA application developed using AngularJS. Access to the application can take place in two ways:

1),通过输入地址(例如) www.example.com

1) By entering the address (example) www.example.com, or

2)点击像 http://www.example.com?do=this&param=1234

在启动应用程序时,它会检查URL,如果合适的参数被发现,它会提示用户登录/注册,然后进入到一个特定的页面,访问者应该进行一些活动的应用程序内相关行动这个带参数 1234

When the application is started, it examines the URL and, if suitable parameters are found, it prompts the user to log-in/register and then goes to a specific page within the application where the visitor is supposed to perform some activities related to the action this with parameter 1234.

通过网页遍历是由JavaScript命令处理:

Traversal through pages is handled by the javascript command:

$ window.location.href =#/ other_page;

此工程确定到目前为止,除了该URL被保持与参数。因此,每当应用程序决定它需要去到另一个网页,网址(在浏览器的地址栏中)看起来像:

This works ok so far, except that the URL is kept with the parameters. As such, whenever the application decides that it needs to go to another page, the URL (in the address bar of the browser) would look like:

http://www.example.com?do=this&param=1234#/other_page

被搞乱了应用程序的行为。

which is messing the behavior of the application.

我的问题是:一旦我能够从原始URL中提取收到的参数,我想为洁净的网址,并用其正常的内容进行,这将是这样的:

My question is: Once I was able to extract from the original URL the received parameters, I want to clean the url and proceed with its normal contents, which would be something like:

HTTP://www.example.com#/other_page

如何才能实现这一目标?

How can this be achieved?

先谢谢了。

推荐答案

只是找到了一个可行的解决方案。我用下面的命令:

Just found a working solution. I use the following command:

$window.location.href = location.protocol          + 
                        "//"                       + 
                        location.host              + 
                        "/index.html#/other_page"    ;

这使的伎俩。也许不是最优雅,但它的工作原理是必要的。

which makes the trick. Perhaps not the most elegant, but it works as needed.

感谢你们(@vivek和@prakashA)的支持。

Thank you guys (@vivek and @prakashA) for your support.

这篇关于角JavaScript的清洁网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆