Router - load url directly?

239 views
Skip to first unread message

Jason Clark

unread,
Sep 17, 2013, 4:17:12 PM9/17/13
to duran...@googlegroups.com
So here's possibly one of the dumbest questions ever asked on this group: Is it possible with the router in 2.0 to give it a route that maps to an external URL?

Here's what I'm trying to do: I'm using Durandal for our main company site, and I'd like to add a link to a sister company's site in the navigation.  Since the router builds the navigation, I kinda need to include it in the routes, I think.  If there's a better way to do this, please let me know.

Rob Eisenberg

unread,
Sep 17, 2013, 4:19:42 PM9/17/13
to Jason Clark, duran...@googlegroups.com
I would just add a static link and not worry about involving the router or databinding.


On Tue, Sep 17, 2013 at 4:17 PM, Jason Clark <riceb...@gmail.com> wrote:
So here's possibly one of the dumbest questions ever asked on this group: Is it possible with the router in 2.0 to give it a route that maps to an external URL?

Here's what I'm trying to do: I'm using Durandal for our main company site, and I'd like to add a link to a sister company's site in the navigation.  Since the router builds the navigation, I kinda need to include it in the routes, I think.  If there's a better way to do this, please let me know.

--
You received this message because you are subscribed to the Google Groups "DurandalJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to durandaljs+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Rob Eisenberg,
President - Blue Spire
www.durandaljs.com

Jason Clark

unread,
Sep 17, 2013, 5:05:24 PM9/17/13
to duran...@googlegroups.com, Jason Clark, r...@bluespire.com
Well, instead, I used the router, but paid attention to the navigation I was using.  In essence, I added a route with no ModuleID, a hash of the URL I was pointing to (as in my navigation I was setting href = hash) and a title.  That fixed the issue entirely.

Thanks for encouraging the static link, as it actually made life easier for me.  (BTW, the reason I didn't just use a static link is that my navigation is (like most I think) in a foreach databound ul. Adding the static link would have wreaked havoc on my links, I think.)

George P

unread,
Mar 20, 2014, 10:03:17 AM3/20/14
to duran...@googlegroups.com, Jason Clark, r...@bluespire.com
Rob/Jason,

Actually I just created a custom binding for this very purpose. It works beautifully well and I think it fits perfectly with how Knockout wants you to approach DOM interaction (I certainly view adding a hyperlink as a DOM interaction).

So this is what I do:

<span class="url" data-bind="externalUrl: { url: website, abbreviate: true, showPopup: true, maxLength: 25 }"></span> 

The binding creates an anchor tag on the fly if website exists, or removes the anchor (after verifying that the anchor is already present) if it does not. I also do other things, like optionally strip out protocol and even "www" to conserve display real estate.

I hope this helps.

Durandal ROCKS! It's so enjoyable to work with. Thanks for all of your work Rob!

George
Reply all
Reply to author
Forward
0 new messages