0

I am trying to redirect invalid urls with the following

angular.module('myApp').config(function($stateProvider, $urlRouterProvider) {

 $urlRouterProvider.otherwise('/login');

  $stateProvider
    .state('test',{
      url:'/test',
      templateUrl: 'views/test.html'
    })
    .state('login',{
      url:'/login',
      templateUrl: 'views/login.html'
    });
  }).

This url gets redirected http://localhost/#/random but this doesn't http://localhost/random and I get

Cannot GET /random 

I think it is because it is outside of angular (no hash #).

How do I catch people typing in random urls and redirect them appropriately?

I don't want to use $locationProvider.html5Mode(true); for browser support issues.

I am using grunt serve for local front-end development and packaging and running with spring boot in production.

opticyclic
  • 7,412
  • 12
  • 81
  • 155

2 Answers2

0

When you type http://localhost/random in your address bar and press Enter, you send a GET request to your server. AngularJS executes in the browser. So it's completely irrelevant.

Your server needs to do what you want (i.e. redirect to /#/login), instead of sending a 404.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
0

You either wan't to redirect to a specific route or page server side. So you need to intercept/override your methods that handle page errors and specifically target the 404.

Really you want to post this under a spring tag.

This may help you

furkick
  • 423
  • 6
  • 18