Skip to content
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

feat(route-config): add support for props and alias #3818

Merged
merged 3 commits into from
Sep 1, 2018
Merged

feat(route-config): add support for props and alias #3818

merged 3 commits into from
Sep 1, 2018

Conversation

farnabaz
Copy link
Member

Currently nuxtjs support some of vue-router route configs and some use fill configs like alias and props is missing

@codecov-io
Copy link

codecov-io commented Aug 29, 2018

Codecov Report

Merging #3818 into dev will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev    #3818   +/-   ##
=======================================
  Coverage   97.84%   97.84%           
=======================================
  Files          18       18           
  Lines        1162     1162           
  Branches      317      317           
=======================================
  Hits         1137     1137           
  Misses         24       24           
  Partials        1        1

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aeb33e0...880e184. Read the comment docs.

@@ -11,6 +11,9 @@ import Router from 'vue-router'
res += (route.component) ? ',\n\t' + tab + 'component: ' + (splitChunks.pages ? route._name : `() => ${route._name}.default || ${route._name}`) : ''
res += (route.redirect) ? ',\n\t' + tab + 'redirect: ' + JSON.stringify(route.redirect) : ''
res += (route.meta) ? ',\n\t' + tab + 'meta: ' + JSON.stringify(route.meta) : ''
res += (typeof route.props !== 'undefined') ? ',\n\t' + tab + 'props: ' + (typeof route.props === 'function' ? serialize(route.props) : JSON.stringify(route.props)) : ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, this may be simplified into (route.props)

Copy link
Member Author

@farnabaz farnabaz Aug 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to vue-router docs, props can have Boolean value, so we can't just check its falsy value

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@farnabaz Regardless, route.props != null is the canonical way of checking null/undefined values in javascript. According to clean-code rules, checking for positive instead of negative is considered slightly easier to read. Robert C. Martin

If doesn't appear to be anywhere where null is accepted instead of undefined, so the code should be:

res += route.props == null ? '' : ',\n\t' + tab + 'props: ' + (typeof route.props === 'function' ? serialize(route.props) : JSON.stringify(route.props))

Right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dotnetCarpenter You're right. I'll create a new pull request to cleanup my code.
Thank you very much for your comment :)

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding a comment link to the API source for better maintenance: https://router.vuejs.org/api/#routes

@pi0 pi0 requested review from Atinux and clarkdo August 30, 2018 09:11
Copy link
Member

@clarkdo clarkdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

BTW, @farnabaz would you mind opening a pr for updating docs ?

@pi0
Copy link
Member

pi0 commented Sep 1, 2018

We can add docs to api/extendRoutes section: https://github.com/nuxt/docs/blob/2.0/en/api/configuration-router.md#extendroutes

@pi0 pi0 merged commit bceddf5 into nuxt:dev Sep 1, 2018
@lock
Copy link

lock bot commented Nov 23, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 23, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants