2

I have an application that does not get deployed at the root of our site, it lives at site.com/TRAP_beta and a component route defined like this { path: '', component: TrapFormComponent }. I set the base url tag as <base href="/TRAP_beta/">.

When I navigate to site.com/TRAP_beta all is good with the world and the application works as intended, but if I navigate to site.com/trap_beta or any other cased version of the url, then router cannot find the path and it breaks.

How do I go about making the urls case insensitive to angular 2?

1

2 Answers 2

1

I ended up dynamically making the base element in a script tag that runs before anything else gets loaded.

    var path = location.pathname.substr(1).match(/[a-z_0-1]*/i)[0];
    var base = document.createElement('base');
    base.href = '/' + location.pathname.substr(1).match(/[a-z_0-1]*/i)[0] + '/';
    document.head.appendChild(base);

This seems to be resolving my issue and allowing me to continue to use router.navigate over navigateByUrl.

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

1 Comment

0

Try to use router.navigateByUrl('/'+'nextValue'); instead of router.navigate(['nextValue']);.Because the instruction will be get based upon the URL provided.

3 Comments

What about the initial load of the application? The route with the path '' doesn't even load if you don't go to TRAP_beta over any other variation.
I can't say much about with out looking into your code.Did you try to change the method to navigatebyUrl where you tried to navigate explicitly
None of this was an issue with navigate links. The app itself threw an error before rendering a single component because it couldn't resolve any routes if the base url wasn't the same case sensitivity as what you put in.

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.