0

I am migrating to ui-router in Angular 1.5 and I need to setup the state provider so when I enter the base URL for my app it goes to my home state, but if user enters some non-existing path, it shows a custom "404" template.

If I set the default state with urlProvider.otherwise(), I can no longer set the 404 template, and if I set up a state with url: "" and set up urlProvider.otherwise() for showing 404 template, then the base url will show the 404 template always.

How can I correctly configure this?

CesarD
  • 573
  • 14
  • 30
  • 1
    Check this http://stackoverflow.com/q/27958051/1679310 – Radim Köhler Dec 06 '16 at 09:42
  • Are you using the legacy version or the 1.0 beta 3? – Vi100 Dec 06 '16 at 10:34
  • @RadimKöhler: I'll check it out now. – CesarD Dec 06 '16 at 12:44
  • @Vi100: I'm using the current stable one (I think it's 0.3.1 or 0.3.2). Definitely not 1.0. – CesarD Dec 06 '16 at 12:44
  • 1
    @CesarD I think that referenced Q & A should cover your needs.. good luck with UI-Router ;) – Radim Köhler Dec 06 '16 at 12:45
  • 1
    Use a state with url: '/' for the root, and otherwise for the rest – Vi100 Dec 06 '16 at 12:55
  • Indeed, that's what I just did based on Radim Köhler linked answer. I set my "home" state with url: '/', and set `$urlRouterProvider` like this: `$urlRouterProvider .when('', '/') .otherwise(function ($injector, $location) { $injector.invoke(['$state', function ($state) { $state.go('notfound'); }]); });` Worked like a charm!! Thanks a lot! – CesarD Dec 06 '16 at 13:08

1 Answers1

0

Simply create a 404 state. Check this out. If you have a different url for a home state than your base url, you can use

urlProvider.when('base-url', 'home-state-url');

Then you can remove the urlProvider.otherwise()

Murwa
  • 2,238
  • 1
  • 20
  • 21