NVO
NVO

Reputation: 2703

Angular UI Router remove slash in ? parameter

Currently I have this issue: Angular ui route stateparam in substate

After some tries with route params and other methods in the url of the state like {transactionid} and [transactionid] I noticed that there is an / added before the ? of the parameter. So, the URL look liks:

website.com/page/?transactionid=someid

but, I think it must be

website.com/page?transactionid=someid

We currently remove the trailing slash of any url using this code

$urlMatcherFactoryProvider.strictMode(false);

$urlRouterProvider.rule(function($injector, $location) {
    var path = $location.path();
    var hasTrailingSlash = path[path.length-1] === '/';

    if(hasTrailingSlash) {
        //if last charcter is a slash, return the same url without the slash  
        var newPath = path.substr(0, path.length - 1); 
        return newPath; 
    }
});

But, how can I remove the '/' before an 'question' mark?

The route for 'payment-success' (see question in link) currently looks like:

.state('shop.payment-success', {
    url: '/payment-success{transactionid}',
    templateUrl: '/views/payment-success.html',
    params: {
        transactionid: {
            value: null,
            squash: true
        }
    },
    resolve: {
        transactionid: ['$stateParams', function($stateParams){
            console.log($stateParams);
            return $stateParams.transactionid
        }]
    }

Upvotes: 2

Views: 2051

Answers (1)

federico scamuzzi
federico scamuzzi

Reputation: 3778

I think it's better to use the standard routing (you have more options and it's more easy..and don't have to remove nothing).. something like:

.state('shop.payment-success', {
    url: '/payment-success/:value/:squash', //<-- HERE YOU SET THE PARAM .. YOU CAN HAVE MORE THAN ONE
    templateUrl: '/views/payment-success.html',

    resolve: {
        transactionid: ['$stateParams', function($stateParams){
            console.log($stateParams);
            return {value:$stateParams.value,squash:stateParams.squash}
        }]
    }

Upvotes: 0

Related Questions