3
.state('signup', {
        url:'/app/signup/:ref',
        templateUrl: 'partials/signup.html',
      })

Above is my route config using ui-route. It works when I visit localhost:80/signup/something

but I also want it to work when I visit just localhost:80/signup, how do I do that?

2 Answers 2

2

Your configuration is right, the parameters could be optional.

You can also use squash:

.state('signup', {
    url: '/app/signup/:ref',
    templateUrl: 'partials/signup.html',
    params: {
        ref: {squash: true, value: null}
    }
})

squash configures how a default parameter value is represented in the URL when the current parameter value is the same as the default value

see more here: Angular ui.router, Creating an Optional First Path Param

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

1 Comment

Wow, I never saw this mentioned in the docs. I think only ref should have a colon in the url.
0

You have another state with that url:

.state('another-state', {
  url: '/app/signup',
  templateUrl: 'partials/signup2.html'
})

That should make your localhost:80/signup work as you require.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.