0

I've got a page that has a base URL of /foo/ and have set up my state to expect a param.

So, if the user hits /foo/user1/, user1 is the param.

Is it possible to watch for both types of urls? For example, can I declare /foo/user1/ and /foo/user1 (notice, there's no forward slash) in the same state or do I need to create another state to specifically watch for the trailing slash?

Currently, it can be one or the other, but not both. Is that an accurate statement, or am I missing something in the documentation?

1

1 Answer 1

2

if you are using latest version of ui-router add this in your config block $urlMatcherFactoryProvider.strictMode(false) but for older versions of ui-router add this code

$urlRouterProvider.rule(function ($injector, $location) {
    var path = $location.url();

    // check to see if the path already has a slash where it should be
    if (path[path.length - 1] === '/' || path.indexOf('/?') > -1) {
        return;
    }

    if (path.indexOf('?') > -1) {
        return path.replace('?', '/?');
    }

    return path + '/';
});

you should checkout their FAQ area, there is a dedicated section for trailing slash

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

1 Comment

That rule was exactly what I was looking for. I'm using the latest version, but $urlMatcherFactoryProvider.strictMode(false) wasn't doing the behavior I was looking for. Thanks for providing both options, wish I could vote this answer twice!

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.