0

I'm trying to get ui.router to work with the following setup.

export class Router { /* tslint:disable no-unused-variable */ private static $inject: string[] = ["$stateProvider", "$urlRouterProvider", "$locationProvider"]; /* tslint:enable no-unused-variable */ constructor($state: ng.ui.IStateProvider, $urlRouter: ng.ui.IUrlRouterProvider, $location: ng.ILocationProvider) { $urlRouter.otherwise("/"); $state.state("default", { url: "/", views: { "header": { templateUrl: "/views/layout/header.html" }, "sidebar": { templateUrl: "/views/layout/side-menu.html" }, "": { templateUrl: "/views/workspace/index.html" }, "footer": { }, } }); $location.html5Mode(true); } } 

Here is the partial file I'm using.

<div id="workspace"> <div id="workspace-header"> <div data-ui-view="header"></div> </div> <div id="workspace-container"> <div> <div data-ui-view="sidebar"></div> </div> <div> <div> <div> <div id="workspace-view"> <div data-ui-view></div> </div> <div id="workspace-footer"> <div data-ui-view="footer"></div> </div> </div> </div> </div> </div> </div> 

I'm not sure it's related (or whether it's a problem) but the html above is injected using ng-include like so.

<div id="dashboard" data-ng-include="'/views/master.html'" data-prevent-touch-scroll></div> 

Just to be clear I verified that the router gets called.

I thought that 'otherwise' would navigate to the url and it would transit into the default state which will inject the partial views but it doesn't seems to work, I'm sure I'm missing something but I cannot figure it out.

7
  • In these case, plunker would always help. Does it work without html5? Commented Oct 13, 2014 at 6:12
  • I'll make an example and update it. Commented Oct 13, 2014 at 6:19
  • I tried to make this work in Plunker but it seems like it throws 404 for my style.css and app.js.. Commented Oct 13, 2014 at 7:42
  • Which version of Angularjs are you using? Have you tried this: stackoverflow.com/questions/17200231/… Commented Oct 13, 2014 at 7:55
  • I'm using version 1.3.0-rc.5. I do have the base tag as part of my page, it seems like a problem with ng-include. Commented Oct 13, 2014 at 8:03

1 Answer 1

0

I solved it by replacing ng-include with ui-view.

<div id="dashboard" data-ui-view data-prevent-touch-scroll></div> 

My router looks like this.

export class Router { /* tslint:disable no-unused-variable */ private static $inject: string[] = ["$stateProvider", "$urlRouterProvider", "$locationProvider"]; /* tslint:enable no-unused-variable */ constructor($state: ng.ui.IStateProvider, $urlRouter: ng.ui.IUrlRouterProvider, $location: ng.ILocationProvider) { $urlRouter.otherwise("/"); $state.state("default", { url: "/", templateUrl: "/views/master.html", onEnter: ["$state", "$timeout", ($state: ng.ui.IStateService, $timeout: ng.ITimeoutService) => { $timeout(() => { $state.go("default.master"); }); }] }); $state.state("default.master", { views: { "header": { templateUrl: "/views/layout/header.html" }, "sidebar": { templateUrl: "/views/layout/side-menu.html" }, "": { templateUrl: "/views/workspace/index.html" }, "footer": { }, } }); $location.html5Mode(true); } } 

I'm not sure whether it's a solution or a hack but it works. :)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.