Routes Laravel / Angular $routeProvider

Asked

Viewed 390 times

0

I have something like this in my app.js:

app.config( function( $routeProvider ) {
    $routeProvider.when('evento/:id/:caminho', {
        templateUrl: 'views/evento.html',
        controller: 'PrincipalEventoController'
    });
    $routeProvider.when('evento/:id/:caminho/sobre', {
        templateUrl: 'views/sobre.html',
        controller: 'SobreEventoController'
    });

On the route of the Laravel is localhost:8000/evento/1/nome-do-evento. I have a div with ng-view on the page.

The problem is that I share it with ng-view is not loading the content I want. Neither the view, nor the controller defined in the app.js. It always gives the message "Sorry, the page you are Looking for could not be found". I believe that the solution is simple, but I am not succeeding and I decided to ask for the help of the masters.

Hug to all.

1 answer

1

David,

Your conception is wrong. The routes created in Laravel (PHP Framework) has nothing to do with the routes created with Angularjs (Javascript Framework), already established communication between Angular and Laravel is what happens.

In the Laravel with Angular, is created the Views Html inside the briefcase public/html (or it can be any folder name inside the folder public), that is, it is not necessary to go through the controller already seen that are html snippets with tags of Angular

If Javascript (Angular) code would look like this:

app.config( function( $routeProvider ) 
{

    $routeProvider.when('evento/:id/:caminho', 
    {
        templateUrl: '/html/evento.html',
        controller: 'PrincipalEventoController'
    });

    $routeProvider.when('evento/:id/:caminho/sobre', 
    {
        templateUrl: '/html/sobre.html',
        controller: 'SobreEventoController'
    });

});

And your folder organization would be like this:

inserir a descrição da imagem aqui

In this image demonstrates inside the briefcase public to briefcase html with the HTML file clientes.html, this being an example demonstrating the correct location of the html of his angular app

Your link to call the items created in the Standard would be

<a href="#/evento/1/caminho" aria-controls="evento" role="tab" data-toggle="tab">Eventos 1 Caminho</a>

Follow this example by changing to templateUrl like I told you about the folder and normally run by creating a link as shown in the example...

Browser other questions tagged

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