随着违约参数我怎么重写URL? [英] With defaulted parameters how do I rewrite the url?

查看:129
本文介绍了随着违约参数我怎么重写URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了一个日期的可选参数,格式为 YYYY-MM-DD 的路线。如果没有提供一个日期,我会提供当天的日期。
我定义我的路线,像这样:

I have a route that has an optional parameter of a date in the format YYYY-MM-DD. If a date is not supplied, I will supply today's date. I defined my route like so:

  .state('some.report', {
    url: '/report/:reportDate',
    templateUrl: 'app/report/report.html',
    params:{reportDate:moment().format('YYYY-MM-DD')},
    controller: 'reportCtrl',
    })

这工作,在控制器的参数确实是今天的日期,但网址仍然是的http://本地/一些/报告/ 我怎样才能改变它,以便该网址将成为:: 的http://本地/一些/报告/ 2015年2月23日

This works, the parameter in the controller is indeed today's date, but the url remains as http://local/some/report/ How can I change it so that url becomes:: http://local/some/report/2015-02-23

推荐答案

我会说,你的状态定义应该工作,作为表演的此工作示例

I would say, that your state definition should work, as shows this working example

我们还可以设置强制的 南瓜:假

We can also force it with a setting squash: false

    .state('some_report', {
      url: '/report/:reportDate',
      templateUrl: 'tpl.html',
      params: {
        reportDate: {
          value: moment().format('yyyy-MM-dd'),
          squash: false,
        }
      },
      controller: 'reportCtrl',
    });

更多关于这在DOC:的 API参考$ stateProvider

壁球 - {布尔|字符串=} 壁球配置默认的参数值是如何重新$ P $在URL psented当当前的参数值是一样的默认值。如果未设置壁球,它使用默认配置南瓜政策。 (见defaultSquashPolicy())

squash - {bool|string=}: squash configures how a default parameter value is represented in the URL when the current parameter value is the same as the default value. If squash is not set, it uses the configured default squash policy. (See defaultSquashPolicy())

有三个壁球设置:


      
  • :该参数的默认值是不挤压。它是连接codeD和包含在URL

  •   
  • 真正:从URL省略该参数的默认值。如果该参数是在国家的URL声明斜线pceeded跟着$ P $,那么这些斜线之一被省略。这可以允许更干净外观的URL。

  •   
  • <任意字符串>中:该参数的默认值将被替换为您选择的任意占位符

  •   
  • false: The parameter's default value is not squashed. It is encoded and included in the URL
  • true: The parameter's default value is omitted from the URL. If the parameter is preceeded and followed by slashes in the state's url declaration, then one of those slashes are omitted. This can allow for cleaner looking URLs.
  • "<arbitrary string>": The parameter's default value is replaced with an arbitrary placeholder of your choice.

检查一下这里

这篇关于随着违约参数我怎么重写URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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