链接中没有标签的AngularJs路由? [英] AngularJs Routing without hashtag in link?

查看:23
本文介绍了链接中没有标签的AngularJs路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始学习用于 Web 开发的 AngularJs,到目前为止我很喜欢它.但是,我不太确定在视图之间路由时是否在链接中添加主题标签.我主要关心的是谷歌将如何缓存网站上的页面以及链接是否可以双向工作,即用户是否只需点击 www.sampledomain.com/#/orders/450 并直接定向到订单页面.这是一个好的方法还是有一种方法可以在没有主题标签的情况下路由视图?

I've recently began learning AngularJs for web development and am loving it so far. However, I'm not so sure about having hashtags withing the link when routing between views. My main concern is how Google will cache the pages on the site and whether the links will work both ways, i.e. whether users can just click www.sampledomain.com/#/orders/450 and be directed straight to the order page. Is this an okay method or is there a way to route views without the hashtag?

当我删除主题标签时,重新加载页面并出现 404 错误.谁能给我一个体面的解释是怎么回事.谢谢

When I remove the hashtag, the reload the page and gets 404 error. Can anyone give me a decent explanation of what is going on. Thanks

推荐答案

当我删除主题标签时,重新加载页面并出现 404 错误

When I remove the hashtag, the reload the page and gets 404 error

那是因为在您的服务器端代码中,您可能没有处理像www.sampledomain.com/orders/450"这样的请求

That's because in your server side code you are probably not handling a request like "www.sampledomain.com/orders/450"

您可以通过将重定向返回到新 URL(www.sampledomain.com/#/orders/450")或直接返回正确的 HTML 来让服务器端代码处理此请求.正确"的解决方案取决于您的需求.

You can have your server-side code handle this request by either returning a redirect to the new URL ("www.sampledomain.com/#/orders/450") or just return the correct HTML directly. The "right" solution will depend on your needs.

这篇关于链接中没有标签的AngularJs路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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