Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to AngularJS ui-router

I've just started a new project. I'm building a web application, "with native feel", that is going to be run on a remote controlled device in a fullscreen browser (no address bar, fixed resolution). The UI basically consists of multiple fullscreen views. AngularJS is currently the weapon of choice because multiple reasons. I've been trying 'ui-router' and its 'states' to construct the different views. For example:

/#/desktop
/#/menu
/#/videoStore/posterView
/#/videoStore/listView

I very much like having a template, a controller and a URL per view. The fact that the page does not reload when switching views is paramount. However, there are some things I lack.

Double Buffering

I want to be able to prepare the next state/view before transitioning to it. ui-router offers a series of events that will not do. onEnter, $stateChangeStart and $stateChangeSuccess are all called before the state/view controller is even constructed. I'd rather these events where called on the controller before transition. For example onStart when it is first started and onResume on resume.

History behaviour

The state seems to be reconstructed every time I enter it, meaning the template is again added to the DOM and a new controller is instantiated. That is unnecessary and should kill performance. There is no need to reconstruct the menu when leaving the videoStore. Infact, I want to to be able to have it exactly the same, with focus on the same item in subfolders and such without have to recreate it.

Keyhandling

I haven't figured out how to make sure keys go to the right state/view or subview either. I was considering adding a listener to body and then sending the keys to the current scope. Although I do not think that will do because of the uncertainty of which scope is "active" when having multiple views within a state. Some kind of a onFocus event on the state/view controller would be great. Also, there seems to be no way of getting the "active" scope from angular unless traversing $$ (private) fields.

Alright. Thanks for reading.

Here are my questions:

  • Is their some way to "make do" with ui-router? I've only evaluated it for two days and might have missed plenty.
  • Is there a worthy Angularjs alternative to ui-router out there?
  • Are there any other Javascript frameworks out there that does these things similar to how I describe it?
like image 841
Hampus Avatar asked Dec 17 '14 10:12

Hampus


People also ask

What is ui Router in AngularJS?

Angular-UI-Router is an AngularJS module used to create routes for AngularJS applications. Routes are an important part of Single-Page-Applications (SPAs) as well as regular applications and Angular-UI-Router provides easy creation and usage of routes in AngularJS.

What is the use of ui sref?

A ui-sref is a directive, and behaves similar to an html href . Instead of referencing a url like an href , it references a state. The ui-sref directive automatically builds a href attribute for you ( <a href=...> </a> ) based on your state's url.

What is ui in Router?

UI-Router is the defacto standard for routing in AngularJS. Influenced by the core angular router $route and the Ember Router, UI-Router has become the standard choice for routing non-trivial apps in AngularJS (1. x).


1 Answers

You should be fine with ui-router. Regarding most of the problems listed it seems like you need to just minimize the amount of code you're doing in your controllers and move things out to factories/services/providers. This way you can have tighter control over how the data is fetched.

Regarding the DOM, if you use nested states properly then you shouldn't actually have the navigation or other parts reloading when transitioning between states.

The last point Keyboard Handling is just a difficult problem no matter what the underlying framework. You can check out using directives that change the focus (search around if nothing available does what you need then learn to roll your own, assuming here tabindex isn't good enough).

As is so far as I've seen ngRoute or uiRouter are your options insofar as client side routing are concerned and uiRouter is more feature rich.

Regarding if there are "better" frameworks available, questions that are based mostly on opinion (subjective) or where no parameters are known against which we can judge a technology aren't a good fit for StackOverflow.

like image 111
shaunhusain Avatar answered Oct 01 '22 14:10

shaunhusain