{"action":"created","issue":{"url":"https://api.github.com/repos/angular-ui/ui-router/issues/3098","repository_url":"https://api.github.com/repos/angular-ui/ui-router","labels_url":"https://api.github.com/repos/angular-ui/ui-router/issues/3098/labels{/name}","comments_url":"https://api.github.com/repos/angular-ui/ui-router/issues/3098/comments","events_url":"https://api.github.com/repos/angular-ui/ui-router/issues/3098/events","html_url":"https://github.com/angular-ui/ui-router/issues/3098","id":183944625,"number":3098,"title":"Optional parameter doesn't work","user":{"login":"archasek","id":2247211,"avatar_url":"https://avatars.githubusercontent.com/u/2247211?v=3","gravatar_id":"","url":"https://api.github.com/users/archasek","html_url":"https://github.com/archasek","followers_url":"https://api.github.com/users/archasek/followers","following_url":"https://api.github.com/users/archasek/following{/other_user}","gists_url":"https://api.github.com/users/archasek/gists{/gist_id}","starred_url":"https://api.github.com/users/archasek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/archasek/subscriptions","organizations_url":"https://api.github.com/users/archasek/orgs","repos_url":"https://api.github.com/users/archasek/repos","events_url":"https://api.github.com/users/archasek/events{/privacy}","received_events_url":"https://api.github.com/users/archasek/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-10-19T12:13:30Z","updated_at":"2016-10-20T21:04:28Z","closed_at":"2016-10-20T21:04:28Z","body":"I have something like this:\r\n\r\n```\r\n.state('test', {\r\n    url: '/',\r\n    params: {\r\n        param1: null\r\n    },\r\n   (...)\r\n}\r\n```\r\n```\r\n<a ui-sref=\"test\">\r\n    test1\r\n</a>\r\n<a ui-sref=\"test({ param1: 'abc' })\">\r\n    test2\r\n</a>\r\n```\r\n\r\nTest2 works well.\r\nTest1 doesn't load anything.\r\nI tried also with:\r\n\r\n```\r\nparams: {\r\n    param1: {\r\n        value: null,\r\n        squash: true\r\n    }\r\n},\r\n```\r\nDoesn't work unfortunately.\r\n\r\nWhat is the proper way to add optional parameters?\r\n\r\n**EDIT:**\r\n\r\nI recognized that it's because of that I am actually on the same state and url. When I am on the test state with param specified, the sref to state without params doesn't work. Is there any option to force reload when changing the state to one witout params? Something like:\r\n`ui-sref=\"test({ reload: true })`\r\nWhen I use `ui-sref=\"test\" ui-sref-opts=\"{ reload: true }\"` it reloads, but the param is not cleared to defaults (param1: null), it's always set to 'abc', which is weird :(.\r\n\r\nThe only thing that works is:\r\n`ui-sref=\"test({ param1: null })\"`, that's ok, but it would be great if I could use just `ui-sref=\"test\"` and it should load the test state without any parameters."},"comment":{"url":"https://api.github.com/repos/angular-ui/ui-router/issues/comments/255227806","html_url":"https://github.com/angular-ui/ui-router/issues/3098#issuecomment-255227806","issue_url":"https://api.github.com/repos/angular-ui/ui-router/issues/3098","id":255227806,"user":{"login":"christopherthielen","id":2053478,"avatar_url":"https://avatars.githubusercontent.com/u/2053478?v=3","gravatar_id":"","url":"https://api.github.com/users/christopherthielen","html_url":"https://github.com/christopherthielen","followers_url":"https://api.github.com/users/christopherthielen/followers","following_url":"https://api.github.com/users/christopherthielen/following{/other_user}","gists_url":"https://api.github.com/users/christopherthielen/gists{/gist_id}","starred_url":"https://api.github.com/users/christopherthielen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christopherthielen/subscriptions","organizations_url":"https://api.github.com/users/christopherthielen/orgs","repos_url":"https://api.github.com/users/christopherthielen/repos","events_url":"https://api.github.com/users/christopherthielen/events{/privacy}","received_events_url":"https://api.github.com/users/christopherthielen/received_events","type":"User","site_admin":false},"created_at":"2016-10-20T21:04:28Z","updated_at":"2016-10-20T21:04:28Z","body":"you could write a transition hook to force the `inherit` option to false on certain states.\r\n\r\nhttp://plnkr.co/edit/js5RGT7BMxWZf9Vn1hQz?p=info\r\n\r\n```js\r\n\r\napp.run($transitions => {\r\n  let inheritFalseCriteria = { to: (state) => state.inherit === false };\r\n  \r\n  $transitions.onBefore(inheritFalseCriteria, (trans) => {\r\n    let orig = trans.targetState();\r\n    if (orig.options().inherit === true) {\r\n      var options = Object.assign({}, orig.options(), { inherit: false });\r\n      return trans.router.stateService.target(orig.state(), orig.params(), options);\r\n    }\r\n  })\r\n})\r\n```\r\n\r\nClosing because I think the why is answered, and a workable solution provided."}}
{"actor":{"display_login":"christopherthielen"}}