如何实现angular.js定制的路线? [英] how to implement custom routes in angular.js?

查看:114
本文介绍了如何实现angular.js定制的路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个路线:

  .STATE('home.blog',{
  网址:/博客,
  templateUrl:blog.html
  控制器:BlogController
})

和我的路线是本地主机:3000 /主页/博客我想将其更改为本地主机:3000 /博客。我在网上搜索了,但我还没有找到任何简单的解决办法。


解决方案

这是因为URL的一部分是由父母dervied。但是,我们可以明确地设置,即家长不应使用' ^

  .STATE('home.blog',{
  网址:^ /博客,
  templateUrl:blog.html
  控制器:BlogController
})

查看文档

绝对路线(^)


  

如果您想拥有绝对的URL匹配,那么你就需要preFIX你的URL字符串用特殊符号'^'。


  $ stateProvider
  .STATE('联系人',{
     网址:'/联系人',
     ...
  })
  .STATE('contacts.list',{
     网址:'^ /名单,
     ...
  });

I've got a route:

.state('home.blog', {
  url: "/blog",
  templateUrl: "blog.html",
  controller: "BlogController"
})

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.

解决方案

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"
})

See the doc

Absolute Routes (^)

If you want to have absolute url matching, then you need to prefix your url string with a special symbol '^'.

$stateProvider
  .state('contacts', {
     url: '/contacts',
     ...
  })
  .state('contacts.list', {
     url: '^/list',
     ...
  });

这篇关于如何实现angular.js定制的路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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