What is the difference between `path` and `fullPath` in VueJS router?
In my router.js
file, when I'm using the beforeEach
method, I get path
and fullPath
in the properties of to
and from
parameters. I'm wondering which one I should use for redirection purpose. I've seen both been used and I don't when to use which, and what is the difference between both.
An exemple:
export default new Router(
mode: 'history',
base: process.env.BASE_URL,
routes: [
path: 'login'
beforeEnter: (to, from, next) =>
console.log(to, from) // the routes
if (User.loggedIn())
next(from.fullPath) // or maybe `from.path`
else
next()
,
]
)
javascript vuejs2 vue-router
add a comment |
In my router.js
file, when I'm using the beforeEach
method, I get path
and fullPath
in the properties of to
and from
parameters. I'm wondering which one I should use for redirection purpose. I've seen both been used and I don't when to use which, and what is the difference between both.
An exemple:
export default new Router(
mode: 'history',
base: process.env.BASE_URL,
routes: [
path: 'login'
beforeEnter: (to, from, next) =>
console.log(to, from) // the routes
if (User.loggedIn())
next(from.fullPath) // or maybe `from.path`
else
next()
,
]
)
javascript vuejs2 vue-router
$route.fullPath :The full resolved URL including query and hash. $route.path:A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar".
– Mars.Tsai
Nov 13 '18 at 10:08
add a comment |
In my router.js
file, when I'm using the beforeEach
method, I get path
and fullPath
in the properties of to
and from
parameters. I'm wondering which one I should use for redirection purpose. I've seen both been used and I don't when to use which, and what is the difference between both.
An exemple:
export default new Router(
mode: 'history',
base: process.env.BASE_URL,
routes: [
path: 'login'
beforeEnter: (to, from, next) =>
console.log(to, from) // the routes
if (User.loggedIn())
next(from.fullPath) // or maybe `from.path`
else
next()
,
]
)
javascript vuejs2 vue-router
In my router.js
file, when I'm using the beforeEach
method, I get path
and fullPath
in the properties of to
and from
parameters. I'm wondering which one I should use for redirection purpose. I've seen both been used and I don't when to use which, and what is the difference between both.
An exemple:
export default new Router(
mode: 'history',
base: process.env.BASE_URL,
routes: [
path: 'login'
beforeEnter: (to, from, next) =>
console.log(to, from) // the routes
if (User.loggedIn())
next(from.fullPath) // or maybe `from.path`
else
next()
,
]
)
javascript vuejs2 vue-router
javascript vuejs2 vue-router
asked Nov 13 '18 at 10:03
Ulysse BNUlysse BN
2,29011231
2,29011231
$route.fullPath :The full resolved URL including query and hash. $route.path:A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar".
– Mars.Tsai
Nov 13 '18 at 10:08
add a comment |
$route.fullPath :The full resolved URL including query and hash. $route.path:A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar".
– Mars.Tsai
Nov 13 '18 at 10:08
$route.fullPath :The full resolved URL including query and hash. $route.path:A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar".
– Mars.Tsai
Nov 13 '18 at 10:08
$route.fullPath :The full resolved URL including query and hash. $route.path:A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar".
– Mars.Tsai
Nov 13 '18 at 10:08
add a comment |
2 Answers
2
active
oldest
votes
From the Vue API Reference:
$route.fullPath
- type:
string
The full resolved URL including query and hash.
$route.path
- type:
string
A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar".
add a comment |
path: A string that is equal to the path of the current route,
always resolved as an absolute path.
Example: /user/11/posts, /user/37/posts
fullPath: The complete URL, including query and hash.
Others...
params: An object that contains key / value pairs of
segments.
query: An object that contains key / value pairs of the
url value string. For example, for
/ foo? user = 1, we have $ route.query.user == 1.
hash: The hash of the current path (without #), if one exists. If
no hash is present, value will be a string
empty.
matched: An Array containing route records for all
nested path segments of the current route. The
route records are the copies of the objects in the
route configuration.
name: The name of the current route, if one exists.
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%2f53278447%2fwhat-is-the-difference-between-path-and-fullpath-in-vuejs-router%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
From the Vue API Reference:
$route.fullPath
- type:
string
The full resolved URL including query and hash.
$route.path
- type:
string
A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar".
add a comment |
From the Vue API Reference:
$route.fullPath
- type:
string
The full resolved URL including query and hash.
$route.path
- type:
string
A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar".
add a comment |
From the Vue API Reference:
$route.fullPath
- type:
string
The full resolved URL including query and hash.
$route.path
- type:
string
A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar".
From the Vue API Reference:
$route.fullPath
- type:
string
The full resolved URL including query and hash.
$route.path
- type:
string
A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar".
edited Nov 13 '18 at 11:06
Ulysse BN
2,29011231
2,29011231
answered Nov 13 '18 at 10:34
user10608712
add a comment |
add a comment |
path: A string that is equal to the path of the current route,
always resolved as an absolute path.
Example: /user/11/posts, /user/37/posts
fullPath: The complete URL, including query and hash.
Others...
params: An object that contains key / value pairs of
segments.
query: An object that contains key / value pairs of the
url value string. For example, for
/ foo? user = 1, we have $ route.query.user == 1.
hash: The hash of the current path (without #), if one exists. If
no hash is present, value will be a string
empty.
matched: An Array containing route records for all
nested path segments of the current route. The
route records are the copies of the objects in the
route configuration.
name: The name of the current route, if one exists.
add a comment |
path: A string that is equal to the path of the current route,
always resolved as an absolute path.
Example: /user/11/posts, /user/37/posts
fullPath: The complete URL, including query and hash.
Others...
params: An object that contains key / value pairs of
segments.
query: An object that contains key / value pairs of the
url value string. For example, for
/ foo? user = 1, we have $ route.query.user == 1.
hash: The hash of the current path (without #), if one exists. If
no hash is present, value will be a string
empty.
matched: An Array containing route records for all
nested path segments of the current route. The
route records are the copies of the objects in the
route configuration.
name: The name of the current route, if one exists.
add a comment |
path: A string that is equal to the path of the current route,
always resolved as an absolute path.
Example: /user/11/posts, /user/37/posts
fullPath: The complete URL, including query and hash.
Others...
params: An object that contains key / value pairs of
segments.
query: An object that contains key / value pairs of the
url value string. For example, for
/ foo? user = 1, we have $ route.query.user == 1.
hash: The hash of the current path (without #), if one exists. If
no hash is present, value will be a string
empty.
matched: An Array containing route records for all
nested path segments of the current route. The
route records are the copies of the objects in the
route configuration.
name: The name of the current route, if one exists.
path: A string that is equal to the path of the current route,
always resolved as an absolute path.
Example: /user/11/posts, /user/37/posts
fullPath: The complete URL, including query and hash.
Others...
params: An object that contains key / value pairs of
segments.
query: An object that contains key / value pairs of the
url value string. For example, for
/ foo? user = 1, we have $ route.query.user == 1.
hash: The hash of the current path (without #), if one exists. If
no hash is present, value will be a string
empty.
matched: An Array containing route records for all
nested path segments of the current route. The
route records are the copies of the objects in the
route configuration.
name: The name of the current route, if one exists.
answered Nov 13 '18 at 10:38
Hamilton GabrielHamilton Gabriel
965
965
add a comment |
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%2f53278447%2fwhat-is-the-difference-between-path-and-fullpath-in-vuejs-router%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
$route.fullPath :The full resolved URL including query and hash. $route.path:A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar".
– Mars.Tsai
Nov 13 '18 at 10:08