Angularjs自动前缀为正斜杠 [英] Angularjs auto prefixes forward slash

查看:134
本文介绍了Angularjs自动前缀为正斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我点击网址说

www.xyz.com/home#route-1

AngularJS自动将其重定向到

AngularJS automatically re-directs it to

www.xyz.com/home#/ route-1

这是 - 它在路径前面加上 / (转发)斜线)

That is - it prefixes the route with a / (forward slash)

为什么会这样?我怎么能停止这样做?

Why is it happening and how can I stop making it do this?

更新
我真正想要的是角度不应该附加正斜杠,也不要删除哈希符号。

Update What I am really looking for is that angular should not attach the forward slash neither remove the hash sign.

推荐答案

@Tushar我不确定你是否已经找到了解决方案,但我也遇到了你的情况,谷歌搜索没有运气。最后我发现这是一个相当简单的修复,我添加了: -

@Tushar I'm not sure if you've figured out a solution but I came across your scenario too and no luck with googling. Eventually I figured out it's a rather simple fix, I've added : -

angular.config(function($locationProvider) {
    $locationProvider.html5Mode({
        enabled: true,
        requireBase: false,
        rewriteLinks: false
    });
})

它只是停止将正斜杠(/)前缀附加到我的哈希锚点。一切都仍然是我们熟悉的(没有用哈希替换URL或什么不是)。

And it just stop appending the forward slash (/) prefix to my hash anchor. Everything remains as what we're familiar with (no replacing of URL with hash or what-not).

这篇关于Angularjs自动前缀为正斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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