justinfagnani / route

A client + server routing library for Dart
BSD 3-Clause "New" or "Revised" License
114 stars 40 forks source link

Example fails to work in Dartium #41

Closed sethladd closed 11 years ago

sethladd commented 11 years ago

screen shot 2013-06-28 at 10 25 03 pm

sethladd commented 11 years ago

I just pulled the master of route, loaded up in Dart Editor, and tried to run the example. This is the failure that I got.

sethladd commented 11 years ago

Here's what I had to do to fix it. Is there a way to ignore the host page as a route? The way the editor works, it serves URLs with the entire path:

~/Code/route[master*]$ git diff
diff --git a/example/example.dart b/example/example.dart
index 3f98941..e835043 100644
--- a/example/example.dart
+++ b/example/example.dart
@@ -3,6 +3,7 @@ library example;
 import 'dart:html';
 import 'package:route/client.dart';

+final example = new UrlPattern('/Users/sethladd/Code/route/example/example.html
 final one = new UrlPattern('/one');
 final two = new UrlPattern('/two');

@@ -13,6 +14,7 @@ main() {
   var router = new Router()
     ..addHandler(one, showOne)
     ..addHandler(two, showTwo)
+    ..addHandler(example, (_) => null)
     ..listen();
 }
justinfagnani commented 11 years ago

It looks like Dartium has changed behavior recently and onPopState is called immediately on page load on the page's URL. Before the example never tried to handle the original location of the file, so there was no handler installed.

I'll come up with some fix, but really, the way router is designed to use pushState and onPopState, it's supposed to be used with nice URLs along with some server-side support (to handle the nice URLs on the server-side), not primarily with with fragments like most other routing packages. Another option is that I just add a server to the example.

justinfagnani commented 11 years ago

Ok, fixed the example with your approach but a pattern that will work for any project location.

sethladd commented 11 years ago

Thanks for taking a look!

sethladd commented 11 years ago

So looks like, to use route, we need to always have a route for the "homepage" of the app.