问题
I'm using email service provider to which backend (microservice arhitecture) is sending various details that are needed to populate email dynamically. One of those details are links such as Deposit here link within an email where, when customer clicks on it he should be redirected to app directly to deposit page.
How actual link looks like for example is:my-app.com/deposit?accountId=1&customerId=10&something=30
What data is passed to email service provider is:my-app.com/email-redirects?page=deposit
The reason why I don't want that backend constructs actual link is because of changes, if I change link on frontend I need to change backend as well. Besides that for many links service that is doing this does not have needed info (query parameters) so this service would need to call other services to get needed info. Frontend should handle this easier.
What I'm trying to do is something like component-less routing, where when path isemail-redirects some piece of logic based on page query parameter should be executed which will create actual link my-app.com/deposit?accountId=1&customerId=10&something=30
The goal of this is that frontend should be able to construct complete actual url based on page parameter calling backend if it needs any additional info such as accountId, customerId, something. As soon as it creates the actual link, logic should just redirect customer to actual url and appropriate component will be rendered. Anyway to achieve component-less routing?
回答1:
Look into UrlMatcher. https://angular.io/api/router/UrlMatcher
Create a custom UrlMatcher for your email-redirects path, and if it matches, return a new UrlSegment with the deposit?accountId=1&customerId=10&something=30 info in it. This new route will be passed to the child router where you will be able to do whatever you want with it.
来源:https://stackoverflow.com/questions/48693104/angular-2-component-less-routing-executing-whatever-logic-when-particular-url-i