angularjs - Angular ui-router bound state to URL -


i'm struggling counfiguration of $stateprovider , $urlrouterprovider days now.

my problem is, in fact, after use $state.go(), state changes normally, url in browser stays same (#/).

additionaly, when set $urlrouterprovider.otherwise('home'); option, after every $state.go() router redirects /home, no matter state picked.


my configuration:

stateconfiguration.$inject = ['$stateprovider', '$urlrouterprovider']; function stateconfiguration($stateprovider, $urlrouterprovider){     $urlrouterprovider.otherwise('home');      addstate("state1", "/state1", "<example-page></example-page>");     addstate("state2", "/state2", "<example-page2></example-page2>");     addstate("register", "/register", "<register-page></register-page>");     addstate("error", "/error", "<error-page></error-page>", {         error: null     });     addstate("mylibrary", "/my-library/{groupid}{groupname}", "<my-library></my-library>", {         groupid: null,         groupname: null     });     addstate("home", "/home", "<main-page></main-page>");     ///////////////////////////      function addstate(statename, url, template, params){         $stateprovider.state(             statename,              {                 url: url,                  template: template,                 params: params || {}             }         );     } } 

can point me, have error? every state uses directive.

my goal when application changes state, url in browser changes well. additionally, when user enter url app.com/state-url, application redirects state url state-url. how should it?


update

as requested, i'm adding $state.go() calls, they're not "big".

service.home = function(params){     $state.go("home", params); };  service.register = function(params){     $state.go("register", params); }; 

also, after looking closer, after going register state, url changes 0.5 s register , then, goes home.

your use of wrong:

$urlrouterprovider.otherwise('home'); 

the clue in name (urlrouterprovider) - deals url, not state, should this:

$urlrouterprovider.otherwise('/home'); 

i can't comment on $state.go calls, because haven't provided examples of those.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -