Disable URL change using UI router in Angular?

Is it possible to configure ui-routerAngular 1.5 in an application to completely ignore the address bar?

The desired behavior looks something like this:

  • Navigating between states through the user interface does not change the URL
  • Changing the URL does not cause navigation between states, only the user interface or program actions (button clicks, etc.)
  • Kick F5 restarts the application from the default controller
  • Source URL (especially request parameters) must be accessible

The UPDATE . I am building an application with a very specific use case, not a website. The usual ways of browsing the web do not apply here. Please accept the requirements as they are, even if it may seem contrary to common sense.

+4
source share
1 answer

I agreed that the claimed approach is not good if we consider the classic web application.

I tried to create an example application tailored to your requirement. This is what my router configuration file (router.config.js) looks like in my fruit application:

.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 conditions:

start: url / is the entry point of my application. If url is /, the startstate will be loaded.

fruits: . , url. , , url ( , URL- ).

fruits.details: id fruitId. , fruitId params. params URL-! , . ui-sref="fruit.details({ fruitId: my-fruit-id })", fruit.details fruitId my-fruit-id.

, , , , .


?

  • URL
  • URL- , ( ..)
  • F5
  • URL ( )

- >

  • pass: url
  • pass: url start. - , start , .
  • pass: start
  • pass: start URL-, .
, : URL- ( startCtrl). url , /start, . URL- , .

Update: OP @Impworks, , url /. , url, .

+3

Source: https://habr.com/ru/post/1654017/


All Articles