ngRoute breaking when accessing a specific url

0

Hello! I have a problem with ngRoute that I can not understand why.

Basically, when I try to access a specific URL from a route, from outside the app (not from an application link), I get the message Can not GET / Route .

My route definition is as follows:

$routeProvider
  .when('/', {
    templateUrl: '/app/views/home.view.html',
    controller: 'MainController'
  })
  .when('/rota', {
    templateUrl: '/app/views/rota.view.html',
    controller: 'RotaController'
  })
  .otherwise({
    redirectTo: '/'
  });

$locationProvider.html5Mode(true);

When access link , it should render the view 'route.view.html', but I get the error Can not GET / route on the screen and this error in the console:

  

Refused to execute inline script because it violates the following   Content Security Policy directive: "default-src 'self'". Either the   'unsafe-inline' keyword, the hash   ('sha256-hzYGow + v / BzJilvlDniVqfrdxCAYE9ApuYT6MnI40fQ ='), or a nonce   ('nonce -...') is required to enable inline execution. Note also that   'script-src' was not explicitly set, so 'default-src' is used as a   fallback.

If I access this route from within the application (via a navbar link, for example), I need to put / # / route to work. The idea of html5Mode would be to get this # from the route, but it is not possible because it gives error without it.

    
asked by anonymous 26.08.2017 / 21:51

1 answer

0

I believe you have not configured your server to rewrite routes to the application.

Generally a basic rule is placed so that if the server receives a request that results in a 404, it redirects to index.html of your app.

When accessing /rota , the server will look for a file in the following path /rota/index.html which will result in a 404 of the server.

By putting the rule to when giving a 404 redirect to its index.html , the server will look for /rota/index.html , but before sending the 404 in the response, it will try to search the index.html defined in rule.

Finding it, index.html will be sent in the response to the /rota route.

So your app will initialize and check that it has the /rota route in the address bar and resolve internally to the correct route within the app.

Take a look at the doc: link

    
29.08.2017 / 19:34