In my Angular project, I am implementing a complex structure of nested states using UI-Router.
I am working on setting up a parent state that will determine the language of the application based on an optional locale path in the URL.
- For Spanish
www.website.com/es/search
- For English
www.website.com/search
The '/es'
is required for Spanish, while English is assumed when the parameter is missing and I would like to avoid having the '/en'
.
I want all child states of this parent state to inherit the selected locale value.
$stateProvider
.state('localization', {
abstract: true,
url: '/:locale?',
params: {
locale: { value: 'en' }
}
})
.state('search', {
url: '/search',
parent: 'localization'
});
I aim to access the $stateParams.locale
in any of the child states seamlessly.