i have this senario :
when use register in site i send a email to that email . in that have a link and must click on that link for verify registertion .
that route have this information :
http://localhost:4200/auth/verify-checking?email={0}&code={1}
and i create this route :
{ path: 'verify-checking', component: CheckingVerifedComponent },
but i have tow problem :
A : can not find the params :
i use this code but not worked :
this.route.params.subscribe(params => {
this.sendModel.email = params['email'];
this.sendModel.code = params['code'];
});
B : it show me this error :
Error: Cannot match any routes. URL Segment: 'auth/verify-checking%3Femail%3Dkianoushvv123456#gmail.com&code%3DCfDJ8PQkunuAtiZOulV9qQ%252F3astuT%252Fa2VVXDAhxbE%252Fpg%252FfmcpXTcFXPR3gunRzs443wcxrxxWefG3PHVqmdbJL5GZX8dwgI0UuZTVDW%25206U2hSNBTQ1X7xT3YHh%2520%2520ym3%252FP3rlinriN4vgxJEMbmqPKQYe7XsnjcjYCtNvHY141nk%252FEYkoj6FZkEPuVdZO5qH%2520jNyRXA%253D%253D'
how can i solve this problems ?????
http://localhost:4200/auth/verify-checking?email={0}&code={1}
queryParam is used for ?email={0}&code={1}
this.route.queryParams.subscribe(params => {
this.sendModel.email = params['email'];
this.sendModel.code = params['code'];
});
You may consider this:
Route
{ path: 'verify-checking/:email/:code', component: CheckingVerifedComponent }
Extracting the Parameters
this.sendModel.email = this.route.snapshot.paramMap.get('email');
this.sendModel.code = this.route.snapshot.paramMap.get('code');
Related
I need to match a route like this: /route*
I mean, one that matches /route1, /route2, /route999, /routewhatever
I don't want to match /route/whatever. I want that if the user puts anything after the main name it's ignored.
/route* didn't work. Is this possible ?
the only way I see is to use a UrlMatcher
export function wildCardMatcher(url: UrlSegment[]) {
return url.length === 1 && url[0].path.startsWith('route') ? ({consumed: url}) : null;
}
and then
{ matcher: wildCardMatcher, component: HomeViewComponent,}
here's a demo
UrlMatcher in Angular lets you define your own function to match a url to a route.
You could do something like
function wildCardMatcher(url: UrlSegment[]) {
return url[0].path.slice(0,5) === 'route' ? ({consumed: url}) : null;
}
routes = [{
matcher: wildCardMatcher,
component: Whatever
}]
https://angular.io/api/router/UrlMatcher
I have a very basic feathers service which stores data in mongoose using the feathers-mongoose package. The issue is with the get functionality. My model is as follows:
module.exports = function (app) {
const mongooseClient = app.get('mongooseClient');
const { Schema } = mongooseClient;
const messages = new Schema({
message: { type: String, required: true }
}, {
timestamps: true
});
return mongooseClient.model('messages', messages);
};
When the a user runs a GET command :
curl http://localhost:3030/messages/test
I have the following requirements
This essentially tries to convert test to ObjectID. What i would
like it to do is to run a query against the message attribute
{message : "test"} , i am not sure how i can achieve this. There is
not enough documentation for to understand to write or change this
in the hooks. Can some one please help
I want to return a custom error code (http) when a row is not found or does not match some of my criterias. How can i achive this?
Thanks
In a Feathers before hook you can set context.result in which case the original database call will be skipped. So the flow is
In a before get hook, try to find the message by name
If it exists set context.result to what was found
Otherwise do nothing which will return the original get by id
This is how it looks:
async context => {
const messages = context.service.find({
...context.params,
query: {
$limit: 1,
name: context.id
}
});
if (messages.total > 0) {
context.result = messages.data[0];
}
return context;
}
How to create custom errors and set the error code is documented in the Errors API.
My goal is to fetch username from a url
Inside app.routing I have route
export const routes: Routes = [
{ path: 'dashboard/:username', component: App }
];
inside appp component I'm trying to fetch this username using
let username = this.route.snapshot.queryParams["username"];
My browser is using localhost:91/dashboard/john
username is always undefined.
You should be using it as params
let username = this.route.snapshot.params["username"];
You don't need to use queryParams here. This is useful when you have something like this:
localhost:91/dashboard?username=john
Just use params property.
this.route.snapshot.params["username"];
I suppose you declared route in following way:
{ path: 'dashboard/:username', component: SomeComponent}
Try this :
this.route.snapshot.params['username']
Instead of queryParams
In my application there are 3 routes as defined below everything is working properly but when then the route which is not defined is called, the blank page is displayed. like, if i enter url http://example.com/page.php/#invalidRoute then i got empty page i want to load
"profile" view if no route is found, my code is given below....
ProfileRouter = Backbone.Router.extend({
initialize : function() {},
routes : {
'' : 'profile',
'detailedProfile' : 'detailedProfile',
'moreReviews' : 'moreReviews',
},
profile : function() {
/*Load a profile*/
},
detailedProfile : function() {
/*Load detail profile*/
},
moreReviews : function() {
/*Load more review*/
}
});
thanks in advance...
You can do something like this. The last route will match everything else that the other routes didn't fulfill. The order of the routes also matters in this case.
routes : {
'' : 'profile',
'detailedProfile' : 'detailedProfile',
'moreReviews' : 'moreReviews',
'*invalidRoute' : 'profile' /* catch all route */
}
This is my routes object in a BackboneJS app:
routes: {
"" : "_navigate",
"home" : "_navigate",
"blog" : "_navigate",
"photos" : "_navigate",
"notes" : "_navigate",
"about" : "_navigate",
"singlepost_:id" : "_navigate"
},
it redirects routes to the _navigate method, which looks like this:
_navigate: function(postId) {
if (postId) {
// show single entry
return;
}
// show regular entry
},
It works perfectly fine. However, I find the repetitive routes object to be annoying.
My question is: Is there a better way to direct all these routes to the same method without repeating yourself so much?
Thanks!
http://backbonetutorials.com/what-is-a-router/ Check out the section on splats
Any "*splats" or ":params" in route definitions are passed as
arguments (in respective order) to the associated function. A route
defined as "/:route/:action" will pass 2 variables (“route” and
“action”) to the callback function. (If this is confusing please post
a comment and I will try articulate it better) Here are some examples
of using ":params" and "*splats"
routes: {
"/posts/:id": "getPost",
// Example
"/download/*path": "downloadFile",
// Download
"/:route/:action": "loadView",
// Load Route/Action View
},
getPost: function( id ){
alert(id); // 121
},
downloadFile: function( path ){
alert(path); // user/images/hey.gif
},
loadView: function( route, action ){
alert(route + "_" + action); // dashboard_graph
}
Quite simple, really.
routes: {
"*actions:_id": "_navigate"
}
Thanks to Jason Strimpel from the BackboneJS Google Group.