ASP.NET MVC 路由-domain.com/Events#!/12 到domain.com/Events/12
我正在使用 Ajax 更新网站中的一些部分,但现在我正在尝试做一些类似于 facebook 的事情。 当我更新某个部分的内容时,问题是我的网址保持不变。如果我看到 Facebook 示例:
http://www.facebook.com/guilhermegeek# !/guilhermegeek?sk=photos
此链接映射到:http://www.facebook.com/guilhermegeek facebook.com/guilhermegeek?sk=photos
我已经知道如何为那些禁用 javascript 的人使用替代方案:
但我不知道如何像 Facebook 的示例一样编写我的路线。
如果我将网址更改为 mydomain.com/News#!/News/12,我应该如何将其路由到 mydomain.com/News/12 ?
谢谢
I'm updating a few sections in a website with Ajax, but now i'm trying to do something similar to what facebook does.
When i update the content of a section, the problem is that my url remains the same. If i see the facebook example:
http://www.facebook.com/guilhermegeek#!/guilhermegeek?sk=photos
This link is mapped to: http://www.facebook.com/guilhermegeek?sk=photos
I already know how to use an alternative for those who have javascript disable: <a onclick="javascript:updatecontent(); return false;" href="">
But what i don't know is how to write my routes like the example of Facebook.
If i change my url to mydomain.com/News#!/News/12, how should i route this to mydomain.com/News/12 ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
网址中
#
(哈希、pund)符号后面的所有内容都决不发送到服务器。服务器只能看到它之前的部分。只有客户端 JavaScript 可以使用window.location.hash
来使用和理解它。因此,如果您想在应用程序中使用类似的内容,您应该保留默认路由不变,然后让一些 javascript 解析#
符号后面的部分,并执行到相应 url 的重定向。所以你的页面中可以有这样的内容:
Everything that follows the
#
(hash, pund) sign of the url is NEVER sent to the server. The server only sees the part before it. Only client side javascript could use and make sense of it usingwindow.location.hash
. So if you want to use something like this in your application you should leave the default route as is and then have some javascript parse the part following the#
sign and perform a redirect to the corresponding url.So you could have something like this in your page: