1

I'm having trouble transitioning to another view state when I only have the full URL path. The ui-router says to use $state.transitionTo or $state.go but those require the state name.

I tried to change the current URL using $location.url(path) but nothing happens.

Is $location.url(path) the correct way, and something is wrong with my setup or is there another way to do it?

Here is my configuration for the home page:

$stateProvider.state( { name: 'home', url: '^/', templateUrl: "/home.html" } ); 

Here is my config for the app.

cgTag.App.Config.Config = function($httpProvider, $locationProvider, $sce) { // Let CakePHP see $http requests as AJAX $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; // use HTML5 non-hash URLs $locationProvider.html5Mode(true); $locationProvider.hashPrefix('!'); // add all the CDN domains to the white list so that URLs are not blocked by Angular. var cdn = cgTag.AppData["Domain"].replace(/^www\./, "http://s*.") + "/**"; $sce.resourceUrlWhitelist(['self', cdn]); }; cgTag.Angular.config(['$httpProvider', '$locationProvider', '$sceDelegateProvider', cgTag.App.Config.Config]); 

If the current browser url is http://www.cgtag.com/movies then calling $location.url("/") should go to the home page, but nothing happens.

3
  • 1
    Can you show the configuration for $urlRouterProvider and $stateProvier and the URL you are trying to navigate to? Commented Sep 24, 2014 at 1:23
  • 1
    Remove the '^' from your state URL. The URLs are just strings not regexes. Commented Sep 24, 2014 at 2:05
  • @Sly_cardinal nope this didn't fix it. Commented Sep 24, 2014 at 2:57

2 Answers 2

1

I needed to call $scope.$apply() after calling $location.url(path).

Could be because the code was in a keydown event handler.

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

Comments

0

you need to use $location.path() instead $location.url()

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.