Is it possible to configure ui-router
in an Angular 1.5 application to completely ignore the address bar?
Desired behaviour is something like this:
UPDATE: I am creating an application with a very specific use case, not a website. Ordinary web browsing practices do not apply here. Please accept the requirements as they are, even if it may seem to contradict common sense.
Agreed that the stated approach is not good if we consider classic web app.
I tried to create a sample application with your requirement in mind. Here is how my router configuration(router.config.js) file looks like in my fruits app:
.state('start', {
url: '/',
templateUrl: '../app/start/start.html',
controller: 'startCtrl as vm',
})
.state('fruits', {
templateUrl: '../app/fruits/fruitshtml',
controller: 'fruitsCtrl as vm',
})
.state('fruits.details', {
params: {
fruitId: undefined
},
templateUrl: '../app/fruits/fruitdetails.html',
controller: 'fruitDetailsCtrl as vm'
})
Explanation of States:
start
:
url / is entry point of my application. If url is /, start
state will be loaded.
fruits
:
This state shows list of fruits in my app. Note that there is no url
defined for this state. So, if we go to this state, url won't change (State will change, but url won't).
fruits.details
:
This state should show detail of a fruit with id fruitId
. Notice we have passed fruitId in params
. params is used to pass parameters without using the url! So, passing of parameters is sorted. I can write ui-sref="fruit.details({ fruitId: my-fruit-id })"
to navigate to fruit.details state and show details of my fruit with fruitId my-fruit-id.
As you might have already got it, the main idea is to use states as means of navigation.
Does my app pass your points?
->
url
for statesstart
. The app will not take user to any different state, but it does changes state to start
or we could say our default state.start
statestart
in your url, you app will got start state.Update:
As pointed by OP @Impworks, solution for 2nd point is also passed if we set url
of our start state to /
. This way, if we append any string to url, the state won't change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With