I think this will accomplish your needs -
MyApp.config(function($stateProvider, $urlRouterProvider) {
// the known route
$urlRouterProvider.when('', '/');
// For any unmatched url, send to 404
$urlRouterProvider.otherwise('/404');
$stateProvider
// Home (default)
.state('default', {
url: '/',
resolve: {
// ...
}
// ....
});
});
I refered to this post. You may need to use a regular expression to handle routes with data.
Instead of the #
in your URL you can use a query string too and grab it via $stateParams
in a state.
Here is how you can do that -
// ....
$stateProvider
.state('default', {
url: '/?data',
templateUrl: 'templates/index.html',
controller: 'defaultCtrl'
})
And then you can use this below to go to home with data -
var toStateData = {
key1: 'value1',
key2: 'value2'
}
$state.go('default', {data: JSON.stringify(toStateData)});
You don't have to stringify the data in $stateParams
but this will allow more options with one parameter. In the defaultCtrl
controller you can get the passed query string like this -
var stateData = JSON.parse($stateParams.data);
var key1 = stateData.key1;
// ....