Angular ui-router: Can you change state without changing URL?

Michael Lewis

The multiple nested views functionality of the ui-router is very nice - you can easily jump from one state of your app to another.

Sometimes you might want to change the URL, but sometimes not. I feel like the concept of state should be separate/optional from routing.

Here's a plunker that shows what I mean. This is a fork of one of the plunkers in the ui-router documentation, with 2 minor changes noted below:

.state('route1', {
        url: "/route", // <---- URL IS SHARED WITH ROUTE2
        views: {
            "viewA": {
                template: "route1.viewA"
            },
            "viewB": {
                template: "route1.viewB"
            }
        }
    })
    .state('route2', {
        url: "/route", // <---- URL IS SHARED WITH ROUTE1
        views: {
            "viewA": {
                template: "route2.viewA"
            },
            "viewB": {
                template: "route2.viewB"
            }
        }
    })

This seems to work - the URL stays the same. Again, how much redundant work is done here? Is this an approved/tested usage?

It would be nice if you could omit the url from a state..

UPDATE: You can omit a url from a state. plunker

Update question: Is this an approved/tested usage?

Nate Abele

You can absolutely have a state without a URL. In fact, none of your states need URLs. That's a core part of the design. Having said that, I wouldn't do what you did above.

If you want two states to have the same URL, create an abstract parent state, assign a URL to it, and make the two states children of it (with no URL for either one).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

UI-router change state without changing url

From Java

AngularJS UI Router - change url without reloading state

From Dev

UI-Router: Change url without loading state or defer loading the state?

From Dev

Angular ui-router change state on scroll

From Dev

Change a url parameter in the current state from ui-sref in angular-ui-router

From Dev

Change a url parameter in the current state from ui-sref in angular-ui-router

From Dev

reload state when you are on same state in angular ui-router

From Dev

Using ui-router to simply launch a function without changing state

From Dev

Using ui-router to simply launch a function without changing state

From Dev

URL is not changing even after the state is changed . `ui-router`

From Dev

Change State without using ui-sref in Angular 2 using ui-router-ng2.(Angular2 & UI-Router-ng2)

From Dev

UI-Router - Change $state without rerender/reload of the page

From Dev

Giving angular material $mdDialog a url in angular ui-router state

From Dev

AngularJS ui-router default state for states without a URL

From Dev

Cannot change state from url bar with ui-router

From Dev

angular ui-router all controllers get reloaded with state change

From Dev

angular ui router, back button does cause state change

From Dev

Angular ui router How to change the html in view of a state

From Dev

Angular UI Router, Menu loses functionality on $state change

From Dev

Angular/UI-Router - How Can I Update The URL Without Refreshing Everything?

From Dev

Angular/UI-Router - How Can I Update The URL Without Refreshing Everything?

From Dev

UI Router changing URL but not page

From Dev

Angular UI-router default state on same URL

From Dev

Angular UI Router - Abstract Parent State with empty Url

From Dev

angular.js ui-router pass variable to state url

From Dev

Angular UI-Router parsing URL that contains slashes as part of state

From Dev

In Angular ui-router nested state url changes,but template is not loading

From Dev

Change ui-view template without changing URL

From Dev

Can't navigate to ui-router state with URL

Related Related

  1. 1

    UI-router change state without changing url

  2. 2

    AngularJS UI Router - change url without reloading state

  3. 3

    UI-Router: Change url without loading state or defer loading the state?

  4. 4

    Angular ui-router change state on scroll

  5. 5

    Change a url parameter in the current state from ui-sref in angular-ui-router

  6. 6

    Change a url parameter in the current state from ui-sref in angular-ui-router

  7. 7

    reload state when you are on same state in angular ui-router

  8. 8

    Using ui-router to simply launch a function without changing state

  9. 9

    Using ui-router to simply launch a function without changing state

  10. 10

    URL is not changing even after the state is changed . `ui-router`

  11. 11

    Change State without using ui-sref in Angular 2 using ui-router-ng2.(Angular2 & UI-Router-ng2)

  12. 12

    UI-Router - Change $state without rerender/reload of the page

  13. 13

    Giving angular material $mdDialog a url in angular ui-router state

  14. 14

    AngularJS ui-router default state for states without a URL

  15. 15

    Cannot change state from url bar with ui-router

  16. 16

    angular ui-router all controllers get reloaded with state change

  17. 17

    angular ui router, back button does cause state change

  18. 18

    Angular ui router How to change the html in view of a state

  19. 19

    Angular UI Router, Menu loses functionality on $state change

  20. 20

    Angular/UI-Router - How Can I Update The URL Without Refreshing Everything?

  21. 21

    Angular/UI-Router - How Can I Update The URL Without Refreshing Everything?

  22. 22

    UI Router changing URL but not page

  23. 23

    Angular UI-router default state on same URL

  24. 24

    Angular UI Router - Abstract Parent State with empty Url

  25. 25

    angular.js ui-router pass variable to state url

  26. 26

    Angular UI-Router parsing URL that contains slashes as part of state

  27. 27

    In Angular ui-router nested state url changes,but template is not loading

  28. 28

    Change ui-view template without changing URL

  29. 29

    Can't navigate to ui-router state with URL

HotTag

Archive