0

I am facing some weird type of behavior with spring boot + angular js while doing routing. Although routing is working but otherwise redirect to is not working.

For example:

I have configured otherwise but its not doing any benefit

Below is my code:

 .config(['$routeProvider','$httpProvider',function ($routeProvider, $httpProvider) {
    $routeProvider.when('/analysis', {
        templateUrl : '../resources/views/includes/dashboard.html',
        controller : "RegistrationController"
    }).when('/', {
        templateUrl : '../resources/views/includes/profile.html',
        controller : "RegistrationController"
    })
    .otherwise({
        redirectTo: '/'
    });
     $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
}]);

I have placed in html

2 Answers 2

0

I would suggest you to take a look at $locationProvider.html5Mode(true).

It tells angularJS to use HTML5 strategy if available. Basically # is required for those browsers who do not support HTML5.

Also, you will be required to configure <base> tag of html.

Even when you will implement these concepts, you will stumble across another issue which I faced as well. If you navigate via href in the application, it would work , but if you copy the url and paste it directly in the browser, you'll get error as it would directly hit the server and will try to find necessary URL mapping on the server.

For more details, you can look at this this question which I asked for this issue

I hope it'll help.

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

2 Comments

Correct by doing this we can never redirect directly on copy paste or on refreshing the browser
@Hara : It can be done by configuring the server side conf.
0

Your problem is more related to SEO-related AngularJS implementation, basically, the solution to this is using the rewrite functionality of Apache or Nginx.

For more information, you can start here.

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.