I think this will fulfill 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 referred to this post . You may need to use regex to process data routes.
Instead of # in your url, you can also use the query string and grab it via $stateParams in state.
Here's how you can do it -
// .... $stateProvider .state('default', { url: '/?data', templateUrl: 'templates/index.html', controller: 'defaultCtrl' })
And then you can use this below to return home with the data -
var toStateData = { key1: 'value1', key2: 'value2' } $state.go('default', {data: JSON.stringify(toStateData)});
You do not need to plan data in $stateParams , but this will allow more parameters with one parameter. In the defaultCtrl controller defaultCtrl you can get the passed query string like this -
var stateData = JSON.parse($stateParams.data); var key1 = stateData.key1;
Ross
source share