Route not working with ui-router - Angularjs 1.6

Asked

Viewed 32 times

0

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

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

I wanted to understand why it doesn’t work....

My code is this:

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

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

 <div ng-view></div>

The java back-end is responsible for redirecting to the main page, after the login is performed.

Follows 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();
}

1 answer

0

With Ui-Router you should use its directive to route and not the default Ngroute directive.

Rather than:

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

You must use:

<div ui-view></div> ou <ui-view></ui-view>
  • Giovane tried here and it didn’t work anyway. The url looks like this: http://localhost:8080/Odonto/#! /main .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.