New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing enhancements #293

Open
SteveSandersonMS opened this Issue Mar 19, 2018 · 26 comments

Comments

Projects
@SteveSandersonMS
Member

SteveSandersonMS commented Mar 19, 2018

This issue is to track routing features we're likely to want to add in the future:

  • Review exactly which parameter constraints we really want to support. For example maybe add regex; maybe remove bool or limit the set of datetime formats more precisely. See #295 for more discussion.
  • Catch-all segments (e.g., /products/{*categoryAndName})
  • 404 handler (it's probably not enough just to have a component that matches /{*anythingElse}, because for SSR you'd want to know it's really not a match so you could actually return a 404)
  • Simple method for accessing querystring/hash values (e.g., via new properties on IUriHelper)
  • Multiple nested routers
  • Outbound URL generation (e.g., <a page=@About>About us</a>, or perhaps just by codegenning methods like <a href=@Products.Url(53)>Duck boots</a> for each @page declaration)
  • In the @page directive, allow the use of compile-time constant expressions, not just literal strings (e.g., #1363).

Also the items from #636 that were not yet finalised:

  • Discover [Route] attributes on types in referenced assemblies that themselves reference Microsoft.AspNetCore.Blazor transitively
  • Discover [Route] attributes on component base classes (i.e., inherit=true)
  • In the Router component, make it simple to subclass and override a virtual method to change the logic for locating the IComponent for a given URL. Currently there's no virtual method for this.
  • Make RouteTable's Routes property get-only
  • Cache route tables per assembly
@kristapsstrals

This comment has been minimized.

kristapsstrals commented Mar 19, 2018

@SteveSandersonMS Thanks for raising this!

@grahamehorner

This comment has been minimized.

grahamehorner commented Mar 20, 2018

is a routine regex constraint on the road map?

@SteveSandersonMS

This comment has been minimized.

Member

SteveSandersonMS commented Mar 20, 2018

Regex constraints: definitely maybe :) We're not in a rush to put in all possible constraints because in practice it's rare that you really need them, so they end up just being friction for developers. It's often only server-side API endpoints that need to be strict about that. It's a matter of seeing what scenarios evolve and what kinds of feature requests we're getting from a wide range of people.

@danroth27 danroth27 added this to the Backlog milestone Mar 24, 2018

@danroth27 danroth27 added this to To Do in Blazor via automation Mar 24, 2018

@dlr1

This comment has been minimized.

dlr1 commented Mar 24, 2018

Would it be possible to define all the routes and destinations in a single place like in other JS frameworks?

@conficient

This comment has been minimized.

Contributor

conficient commented Mar 26, 2018

@dlr1 I believe the routing engine is pluggable so you can replace with any other system you desire.

@dlr1 dlr1 referenced this issue Mar 26, 2018

Closed

Better Router #382

@Nathan-Ryan

This comment has been minimized.

Nathan-Ryan commented Apr 12, 2018

@dlr1 with the ability to nest routes too, perhaps similar to the way angular works with the router-outlet component.

@TheAifam5

This comment has been minimized.

TheAifam5 commented Apr 12, 2018

Also saving states for every route would be nice feature to have ;)

@bastienJS

This comment has been minimized.

bastienJS commented Apr 16, 2018

Please replace 'Multiple nested routers' with 'Unlimited nested routers' else we get the same dilemma they found out later in angular 2 that the router`s nesting skills were limited to sth. like 3 child routers :P

@dlr1

This comment has been minimized.

dlr1 commented May 29, 2018

It would be nice to have some virtual methods that are called at appropriate time to either allow navigation to a page or to dis-allow navigation from a page

@DNF-SaS

This comment has been minimized.

DNF-SaS commented Jun 8, 2018

@SteveSandersonMS
Is it possible to restrict the routing from a certain slug onwards?
(e.g. everything below http://myserver/blazor will be processed, but e.g. http://myserver/otherdata won't?)

@danroth27

This comment has been minimized.

Member

danroth27 commented Jun 12, 2018

@DNF-SaS I believe your looking for support for catch-all segments, which hasn't been implemented yet.

@conficient

This comment has been minimized.

Contributor

conficient commented Jun 15, 2018

Is there anything tracking how routes behave if a user is unauthenticated vs authenticated? In MVC we can use filters on controllers to create secure routes and insecure routes.

@danroth27

This comment has been minimized.

Member

danroth27 commented Jun 15, 2018

@conficient Not currently.

@rpedretti

This comment has been minimized.

rpedretti commented Aug 20, 2018

I'm building a Bing Maps component and it generates lots of anchor tags with href="#". As of version 0.5.1 whenever I click any of those links i get redirected to /. Is there a way to proper handle this?

@RyoukoKonpaku

This comment has been minimized.

Contributor

RyoukoKonpaku commented Aug 20, 2018

@rpedretti for now you don't have a choice but to use JS interop since stopping the click even to propagate isn't possible yet and is tracked here #1073. If I remember you'd need the event that called the click and prevent it propagating via event.stopPropagation() method.

@rpedretti

This comment has been minimized.

rpedretti commented Aug 20, 2018

Thanki you @RyoukoKonpaku! Worked like a charm!

@TheFanatr

This comment has been minimized.

TheFanatr commented Oct 7, 2018

Is there any way to manually implement 404 handling at the moment? Is this just a case of changing some logic in the routing system or would it require some more profound changes? It would be very useful for a project that I am working on.

@TheFanatr

This comment has been minimized.

TheFanatr commented Oct 7, 2018

After combing through some of Blazor's codebase, I think I have a reasonable idea of what needs to be done; would a pull request for something like this be considered, or is it too small? It needs to be made either way for my purposes, but I'd love to submit it to the project if I actually get it working.

@TheFanatr

This comment has been minimized.

TheFanatr commented Oct 7, 2018

I got this to work.

<Router AppAssembly=typeof(Program).Assembly FallbackRoute="/404"/>

Basically, if the router detects that a certain route doesn't exist, it will try to render the route described by FallbackRoute and if FallbackRoute is null or nonexistent, the regular behaviour will be observed, with the only difference being that the exception text will say that it cannot find any component with the fallback route '/<fallback>'.

Also, I specifically made it so that URI displayed by the browser is still what was navigated to originally so that some interop can be done to have behaviour specific to a certain nonexistent URI, such as redirecting if a page moved.

I will make a pull request and post the link here.

@robertsundstrom

This comment has been minimized.

robertsundstrom commented Oct 19, 2018

Will there be some way of configuring the router in Startup?

For instance, I want to be able to add handlers that hook into the router and determine whether a component actually should render, like in the case of authentication.

@SteveSandersonMS

This comment has been minimized.

Member

SteveSandersonMS commented Oct 22, 2018

Yes, the idea is that you'll be able to subclass Router and override a method to put in whatever logic you want to control the URL->component mapping.

@dvdbot

This comment has been minimized.

dvdbot commented Oct 29, 2018

Any ETA when you'll be able to add sort of router hooks for authentication?
Currently checking per page and redirecting when needed...

@shawty

This comment has been minimized.

shawty commented Nov 1, 2018

The ability t attach a user defined object to each route, the same way it can be done in Aurelia would be nice :-)

EG:

Routes[]{name: "index",display: "Index Page",ID: "ID123", showInNav: true,....., userdata: { something, something, something } }

In Aurelia for example, I often use this approach to add roles to a specific route. I then intercept the before navigation event, and compare the roles on the route, to those loaded from the users session, and use that to decide if pages are accessible or not.

There are many other use cases too, such as route language, and dynamic routes.

@robertsundstrom

This comment has been minimized.

robertsundstrom commented Nov 1, 2018

@shawty But then, it is possible that the community will come up with alternative routing libraries, that suit different styles, needs and purposes. It is not a given that Microsoft will handle all the cases. It is a modular and extendable framework.

I'm thinking about building my own routing system that is service-based and configurable from, for instance, Startup.

@shawty

This comment has been minimized.

shawty commented Nov 1, 2018

@robertsundstrom This is true, and I get that :-) I was actually toying with the idea myself.

I do however need to dig into the routing system and take a good look before I do anything else, and (cough, cough blazor devs...) some in depth tech docs on the router on "blazor.net" would be usefull :-)

There are a million ways this could be done, but having just this small feature would be imensly helpfull even to those that are building custom routing systems I think.

@danroth27

This comment has been minimized.

Member

danroth27 commented Nov 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment