本文介绍了如何在 angular.js 中实现自定义路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一条路线:
.state('home.blog', {
url: "/blog",
templateUrl: "blog.html",
controller: "BlogController"
})
我的路由是 localhost:3000/home/blog
我想把它改成 localhost:3000/blog
.我搜索了互联网,但没有找到任何简单的解决方案.
And my route is localhost:3000/home/blog
I would like to change it to localhost:3000/blog
. I searched the Internet but I have not found any simple solution.
推荐答案
这是因为 url 部分源自父级.但是我们可以明确设置,'^' 不应使用该父级:
This is because the url part is dervied from parent. But we can explicitly set, that parent should not be used by '^':
.state('home.blog', {
url: "^/blog",
templateUrl: "blog.html",
controller: "BlogController"
})
查看文档
如果你想有绝对的 url 匹配,那么你需要在你的 url 字符串前加上一个特殊符号^".
$stateProvider
.state('contacts', {
url: '/contacts',
...
})
.state('contacts.list', {
url: '^/list',
...
});
这篇关于如何在 angular.js 中实现自定义路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!