Ui-router adding path to end of existing path - angularjs

I am making an oAuth site that people will land on starting at the path /core/login, and when I make state changes from that page all the urls are being appended to that. Ex. Reset Password has a state url of /core/resetPassword, but what is being displayed is /core/login/core/resetPassword.
What do I need to do to get ui router to append urls to the base url?

Use "core" as a parent state and use "login" and "resetPassword" password as a child states.
.state('core', {
url : '/core',
abstract: true
})
.state('core.login', {
url : 'login',
templateUrl : 'fragments/login.html',
controller : 'LoginController'
})
.state('core.resetPassword', {
url : 'resetPassword',
templateUrl : 'fragments/resetPassword.html',
controller : 'ResetPasswordController'
})

Related

'/:routeparams' is overriding other route in angularjs

app.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl : 'junk.html',
})
. .when('/:pageuniqueid', {
templateUrl : 'page.html',
})
// route for the about page
.when('/first', {
templateUrl : 'first.html',
})
// route for the contact page
.when('/second', {
templateUrl : 'second.html',
});
});
If i type 'example.com/first' in the URL then instead of getting first.html i am getting page.html.
I am implementing the page that user can access directly with their dynamic pageid after base URL.
I want to get page.html only if it is not matched with the other routes. Is there a way to achieve this?
The order of the route definitions matters.
If you define the '/first' route before the '/:pageuniqueid', it should work.
The angular router stops evaluating the routes after the first match.
So in order to get the page.html as a fallback, you should put it as last entry in the list.

angularjs, in a page when we press F5 key or browser refresh again it's not getting to that page instead going to home page always

In our java web application...
We are using angular js 1.4.
$stateProvider for routing .
We have child view inside a parent view.
When we click on browser refresh in any page, whole application getting refreshed and loading from first then it is always redirected to home page instead of that page.
What I want is when we click on F5 or browser refresh in any page it has to redirect to that same page.
I tried with $stateChangeStart,$locationChangeStart
$window.onbeforeload but nothing worked for me.
I don't know why from root it's getting reload
this is parent state
$stateProvider.state('homeView', {
url : '/home',
templateUrl : './home.html',
controller : 'AppController',
data : {
requireLogin : true
}
});
every controller we are reffering parent like this
$stateProvider.state('detailsview', {
url : '/details/:divId',
parent : 'homeView',
templateUrl : './details/details.html',
params : {
'searchCriteria' : null
},
controller : 'CoreMarginDetailsController',
data : {
requireLogin : true
}
});
for state transition we are calling a particular state.
$state.go('detailsview', {
'searchCriteria' : $scope.searchCriteriaData
});

angular ui-router rewrite/redirect url with nginx

i have an angularjs application with ui-router and use nginx.
To create the url for the detail page of a "Track", i use the DB id of this item and the "Track" title. This works great.
If the user change the "Track" title later, the link is broken.
current URL is https://example.com/23345674298/track-title
new URL is https://example.com/23345674298/track-new-title
How can i redirect the website visitor to the change url?
.state('app.track.view', {
url : '/{id}/{title}',
views : {
'content#': {
templateUrl : '/app/components/track/trackView.html',
controller : 'TrackController',
controllerAs: 'vm'
}
}
})

ui-router problems with query string

I have these states:
.state('message', {
url : '/message'
templateUrl : 'views/message.html',
controller : 'messageController'
})
.state('news', {
url : '/news'
templateUrl: 'views/news.html',
controller : 'newsController'
})
In messageController i append some query string in url like /message?contact=some.
problem is that when go to news state with ui-sref, query strings does not cleared and it redirects to /news?contact=some.
i tried to clear $location.search in stateChangeEvent.
any help?
You can do one of the following:
Use query params:
.state('message', {
url: "/message?contact"
// will match to url of "/message?contact=value"
...
}
Use state params: (better for ui-sref linking)
.state('message', {
url: "/message/:contact",
// can be accessed by $stateParams service - $stataParams['contact']
...
}

How to $state.go()

Is my $stateProvider:
$stateProvider
.state('home', {
url : '/',
templateUrl : '/admindesktop/templates/main/',
controller : 'AdminDesktopMainController'
}).state('company', {
url : '/company',
templateUrl : '/admindesktop/templates/grid/',
controller : 'CompanyGridController'
}).state('company.detail', {
url : '/{id:\d+}', //id is
templateUrl : '/admindesktop/templates/company/detail/',
controller : 'CompanyDetailController'
});
It's work for 'company' state (I use ui-sref), but this code not work (called from 'company' state):
$state.go('.detail', {
id: $scope.selectedItem.id //selectedItem and id is defined
});
I read official docs and answers from StackOverflow, but I don't found solution. I can't use ui-sref, I use ui-grid, and new state opened after select one row from table for editing.
What i do wrong?
What would always work is the full state definition:
// instead of this
// $state.go('.detail', {
// use this
$state.go('company.detail', {
id: $scope.selectedItem.id //selectedItem and id is defined
});
In doc there are defined these options, but they depend on CURRENT state:
to string
Absolute state name or relative state path. Some examples:
$state.go('contact.detail') - will go to the contact.detail state
$state.go('^') - will go to a parent state
$state.go('^.sibling') - will go to a sibling state
$state.go('.child.grandchild') - will go to grandchild state
My error is in regular expression, really:
.state('company.detail', {
url : '/{id:\d*}',
templateUrl : '/admindesktop/templates/company/detail/',
controller : 'CompanyDetailController'
})
{id:\d*} worked (integer id).
To load the current state. Check this out.
$state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams
Reference

Resources