3

Angular: 1.1.5

I go to: http://xxxxx.com/route1/route2/route3 and /route3 gets triggered instead of route1/route2/route3 Works fine with HTML5 mode off ... :(

Nginx config

location / {
    index index.html;
    try_files $uri $uri/ /index.html?$args;
}

My app config

$routeProvider.when('/route1/route2/route3', {
        templateUrl: '/views/home.html',
        controller: 'HomeCtrl'
    });

$routeProvider.when('/route3', {
        templateUrl: '/views/home.html',
        controller: 'HomeCtrl'
    });

$locationProvider.hashPrefix('!');
$locationProvider.html5Mode(true);

$location Log:

$$protocol: "http", $$host: "xxxxxx"…}
$$absUrl: "http://xxxxxxx.com/route1/route2/route3"
$$hash: ""
$$host: "10.44.11.73"
$$path: "/route3"
$$port: 80
$$protocol: "http"
$$replace: false
$$url: "/route3"

How can I change my settings to make HTML5 urls working with nested routes?

2 Answers 2

3

For single page apps, this is all you need in your NGINX config:

server
{
    server_name example.com *.example.com;
    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;
    root /var/www/html/example;
    index index.html;
    location / {
       try_files $uri /index.html;
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

This does not fix the problem... $$absUrl: "http://www.locahost/route1/route2/route3" $$path: "/route3" $$url: "/route3" path should be /route1/route2/route3
what is /var/www/html/example here? path to your web app?
3

Add

<base href="/">

to your index.html.

1 Comment

That may help, but I'm not sure why. What would that have to do with html5?

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.