Route not working with ui-router - AngularJS 1.6

0

I have the / main route, which when prompted redirects to an html page. The url is correct but is not loading anything, it remains on the login page.

This route is accessed when the user logs in to the system, in case it is the home page after login.

I wanted to understand why it does not work ....

My code is this:

 /* Configuração de rotas */
 app.config(function($routeProvider) {  
    $routeProvider.when('/main', {
      templateUrl : 'views/public/main.html'
    })
 });

In the main.html page, you have the div with ng-view and the required javascript files being imported.

 <div ng-view></div>

The java backend is responsible for redirecting to the main page after login is done.

Follow the java code:

    private String process(HttpServletRequest request, HttpServletResponse response) throws SQLException{

    String context = request.getServletContext().getContextPath();
    User user = new UserDAO().doLogin(request.getParameter("mail"), request.getParameter("password"));
    JSONObject msg = new JSONObject();
    try {
        HttpSession sessao = request.getSession();
        if (user != null) {             
            sessao.setAttribute("user", user);
            response.sendRedirect(context + "/main");
        } else {
            msg.put("msg", "Erro ao logar");
            sessao.setAttribute("msg", "Usuario ou senha invalido!");
            response.sendRedirect(context + "/index.html?login=invalid");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return msg.toString();
}
    
asked by anonymous 29.08.2017 / 01:21

1 answer

0

With the Ui-Router you should use its policy to do the routing and not the default policy of NgRoute.

Instead of:

<div ng-view></div> ou <ng-view></ng-view>

You should use:

<div ui-view></div> ou <ui-view></ui-view>
    
29.08.2017 / 15:22