Angular 7 - Define routes with queryParams

Multi tool use
I want to declare two Angular routes:
- For a specific item (
/items?id=SOME_ITEM_ID
) - For a list of all items (
/items
)
As the following isn't working, I want to know how I can define my routes to suite my needs?
export const routes: Routes = [
{ path: 'items?id=someItemId', component: ItemComponent },
{ path: 'items', component: AllItemsComponent },
];

add a comment |
I want to declare two Angular routes:
- For a specific item (
/items?id=SOME_ITEM_ID
) - For a list of all items (
/items
)
As the following isn't working, I want to know how I can define my routes to suite my needs?
export const routes: Routes = [
{ path: 'items?id=someItemId', component: ItemComponent },
{ path: 'items', component: AllItemsComponent },
];

1
You can't separate routes by query parameters.
– cgTag
Jan 2 at 16:06
add a comment |
I want to declare two Angular routes:
- For a specific item (
/items?id=SOME_ITEM_ID
) - For a list of all items (
/items
)
As the following isn't working, I want to know how I can define my routes to suite my needs?
export const routes: Routes = [
{ path: 'items?id=someItemId', component: ItemComponent },
{ path: 'items', component: AllItemsComponent },
];

I want to declare two Angular routes:
- For a specific item (
/items?id=SOME_ITEM_ID
) - For a list of all items (
/items
)
As the following isn't working, I want to know how I can define my routes to suite my needs?
export const routes: Routes = [
{ path: 'items?id=someItemId', component: ItemComponent },
{ path: 'items', component: AllItemsComponent },
];


asked Jan 2 at 16:01


FlorianFlorian
53423
53423
1
You can't separate routes by query parameters.
– cgTag
Jan 2 at 16:06
add a comment |
1
You can't separate routes by query parameters.
– cgTag
Jan 2 at 16:06
1
1
You can't separate routes by query parameters.
– cgTag
Jan 2 at 16:06
You can't separate routes by query parameters.
– cgTag
Jan 2 at 16:06
add a comment |
1 Answer
1
active
oldest
votes
I think you don't want queryParams but params, you should define your route like this :
export const routes: Routes = [
{ path: 'items/:id', component: ItemComponent },
{ path: 'items', component: AllItemsComponent },
];
As @cgTag says in comment, queryParams are transparent and you don't need to declare them in route definition.
Okay, I thought it would also be possible to declarequeryParams
. Thank you.
– Florian
Jan 2 at 16:11
1
@Florian, that's not needed. You can write anything inside the queryString and the route will still work (:
– enf0rcer
Jan 2 at 17:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009430%2fangular-7-define-routes-with-queryparams%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you don't want queryParams but params, you should define your route like this :
export const routes: Routes = [
{ path: 'items/:id', component: ItemComponent },
{ path: 'items', component: AllItemsComponent },
];
As @cgTag says in comment, queryParams are transparent and you don't need to declare them in route definition.
Okay, I thought it would also be possible to declarequeryParams
. Thank you.
– Florian
Jan 2 at 16:11
1
@Florian, that's not needed. You can write anything inside the queryString and the route will still work (:
– enf0rcer
Jan 2 at 17:53
add a comment |
I think you don't want queryParams but params, you should define your route like this :
export const routes: Routes = [
{ path: 'items/:id', component: ItemComponent },
{ path: 'items', component: AllItemsComponent },
];
As @cgTag says in comment, queryParams are transparent and you don't need to declare them in route definition.
Okay, I thought it would also be possible to declarequeryParams
. Thank you.
– Florian
Jan 2 at 16:11
1
@Florian, that's not needed. You can write anything inside the queryString and the route will still work (:
– enf0rcer
Jan 2 at 17:53
add a comment |
I think you don't want queryParams but params, you should define your route like this :
export const routes: Routes = [
{ path: 'items/:id', component: ItemComponent },
{ path: 'items', component: AllItemsComponent },
];
As @cgTag says in comment, queryParams are transparent and you don't need to declare them in route definition.
I think you don't want queryParams but params, you should define your route like this :
export const routes: Routes = [
{ path: 'items/:id', component: ItemComponent },
{ path: 'items', component: AllItemsComponent },
];
As @cgTag says in comment, queryParams are transparent and you don't need to declare them in route definition.
answered Jan 2 at 16:05
Louis RLouis R
492212
492212
Okay, I thought it would also be possible to declarequeryParams
. Thank you.
– Florian
Jan 2 at 16:11
1
@Florian, that's not needed. You can write anything inside the queryString and the route will still work (:
– enf0rcer
Jan 2 at 17:53
add a comment |
Okay, I thought it would also be possible to declarequeryParams
. Thank you.
– Florian
Jan 2 at 16:11
1
@Florian, that's not needed. You can write anything inside the queryString and the route will still work (:
– enf0rcer
Jan 2 at 17:53
Okay, I thought it would also be possible to declare
queryParams
. Thank you.– Florian
Jan 2 at 16:11
Okay, I thought it would also be possible to declare
queryParams
. Thank you.– Florian
Jan 2 at 16:11
1
1
@Florian, that's not needed. You can write anything inside the queryString and the route will still work (:
– enf0rcer
Jan 2 at 17:53
@Florian, that's not needed. You can write anything inside the queryString and the route will still work (:
– enf0rcer
Jan 2 at 17:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009430%2fangular-7-define-routes-with-queryparams%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
w3,ughGl p trp0xMbrTB,Xz9kv DT 8if,XnF zV Sx1Jh,OhY P BsIcYnNjVxP9u K7 5 5kda,OEs,6HR99Ct5eDuDIT6YT
1
You can't separate routes by query parameters.
– cgTag
Jan 2 at 16:06