1

I am curretly having trouble understanding ui-router and how exactly I can use it to achieve what I'm after.

I am working on a course manager platform. I have many courses and each course has many videos inside. Generally, my project consists of 2 pages (3 templates - one for courses home page, one for the course item page itself and one for the navigation bar that is an on the course item page).

There are 3 main routes.

  • /courses
  • /courses/:courseslug
  • /courses/:courseslug/:courseitemslug

Right now I have defined 3 states.

 $stateProvider
   // Gets all courses and renders them
   .state('home', {
     url: '/courses',
     templateUrl: '/templates/angular/courses-home.html',
     controller: 'HomeController',
     controllerAs: 'home',
     resolve: HomeController.resolve
   })
   // Does some business logic and redirects to courseitem state
   .state('course', {
     url: '/courses/:courseslug',
     controller: 'CourseController',
     resolve: CourseController.resolve
   })
   // Renders one course item (a video) and an <aside> which the user can use to go through all videos of a course
   .state('courseitem', {
     url: '/courses/:courseslug/:courseitemslug',
     templateUrl: '/templates/angular/courseitem.html',
     controller: 'CourseItemController',
     controllerAs: 'courseitem',
     resolve: CourseItemController.resolve
   });

I use the course state to do some business logic and redirect to the courseitem state.

I have implemented a navbar that lives in the courseitem state which holds all course items for a course and is responsible for fetching a new course items when the users clicks on one.

My biggest problem is: How to not reload the entire state but only the view that holds the video item, so that the navigation bar doesn't have to be reloaded?

For example I want to go from /courses/courseA/video1 to /courses/courseA/video2 without reloading the navigation on the side.

PS: I know that nesting states is a must here but I simply can't get my head around it yet so it is easier for me to do one thing at a time.

zerefel
  • 1,699
  • 2
  • 11
  • 13
  • 1
    Take a look at the answer to this question: http://stackoverflow.com/questions/25349170/multiple-ui-view-html-files-in-ui-router and the plunker. I also have written a simple one today as a plunker for an issue I was having with kendo: http://plnkr.co/lGZypc4qdTKy5i3qXiBD – Mike Cheel Nov 01 '15 at 00:17
  • @Mike Cheel Thanks a lot! The answer to the other question really helped me understand how to achieve what I was after. – zerefel Nov 01 '15 at 16:50
  • My issue in my plunker wasn't about routing but proof of whether ui router was the cause of my problem of which it doesn't look like it was. That's why I don't have any nav in my example. – Mike Cheel Nov 01 '15 at 16:58

0 Answers0