Properly handle notFound URL

We handled notFound URL using an old hack, which no longer works. The
proper way now is to handle a "catch all" route.
This commit is contained in:
Piotr Sarnacki 2014-02-12 07:45:32 +01:00
parent 31d77c1ad9
commit 71e5959f4e
2 changed files with 12 additions and 17 deletions

View File

@ -5,13 +5,7 @@ Ember.Router.reopen
handleURL: (url) ->
url = url.replace(/#.*?$/, '')
try
@_super(url)
catch error
if error.message.match(/No route matched the URL/)
@_super('/not-found')
else
throw(error)
@_super(url)
# TODO: don't reopen Ember.Route to add events, there should be
# a better way (like "parent" resource for everything inside map)
@ -93,7 +87,6 @@ Travis.Router.map ->
@route 'first_sync'
@route 'stats', path: '/stats'
@route 'auth', path: '/auth'
@route 'notFound', path: '/not-found'
@resource 'profile', path: '/profile', ->
@route 'index', path: '/'
@ -101,6 +94,8 @@ Travis.Router.map ->
@route 'index', path: '/'
@route 'profile', path: '/profile'
@route 'notFound', path: "/*path"
Travis.SetupLastBuild = Ember.Mixin.create
setupController: ->
@repoDidLoad()

View File

@ -1,9 +1,9 @@
#module "Router",
# setup: ->
# Ember.run -> Travis.advanceReadiness()
# teardown: ->
# Ember.run -> Travis.reset()
#
#test 'renders notFound template when URL can\t be found', ->
# visit('/somehing/something/something/.../dark/side/..../something/something/something/.../complete').then ->
# equal('The requested page was not found.', $('#main').text().trim())
module "Router",
setup: ->
Ember.run -> Travis.advanceReadiness()
teardown: ->
Ember.run -> Travis.reset()
test 'renders notFound template when URL can\t be found', ->
visit('/somehing/something/something/.../dark/side/..../something/something/something/.../complete').then ->
equal('The requested page was not found.', $('#main').text().trim())