This would be solution with ui-router – working example
$stateProvider
.state('MyState', {
url: '/page-with-form?error',
templateUrl: 'view.page-with-form.html',
controller: 'MyCtrl',
})
The navigation to this state could be like this:
// href
<a href="#/page-with-form">
<a href="#/page-with-form?error=true">
<a href="#/page-with-form?error=false">
//ui-sref
<a ui-sref="MyState({error:null})">
<a ui-sref="MyState({error:true})">
<a ui-sref="MyState({error:false})">
// state.go() - in fact very similar to ui-sref directive
$state.go('MyState', {error: null})
$state.go('MyState', {error: true})
$state.go('MyState', {error:false})
The documentation to url params:
- Query Parameters (small cite)
You can also specify parameters as query parameters, following a ‘?’:
url: "/contacts?myParam"
// will match to url of "/contacts?myParam=value"
Test it in action here