question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mention React usage in Readme

See original GitHub issue

Description

I struggled a lot with the usage in a React Application. The problem was that i don’t want to put the @routes blade directive in the header of my application because everyone can see all routes directly if the source code is inspected.

Due to this i wanted to go with option two to generate the Ziggy file and use it as custom Ziggy in the route() function. In the Readme i could only find the Vue solution to use a mixin for this purpose but nothing related to React.

Suggestion

I wrote a very small helper that did the trick for me. Maybe this one can also be mentioned in the Readme to save some time i someone has the same issue. I called the file ziggyroutes and imported it in my application in the view where i need it. Additionally the helper methods are mentioned in the function like current(), check() and url().

import route from '../../assets/ziggyroute';

console.log(route('user.login')); 
import route from 'ziggy';
import { Ziggy } from './ziggy';

export default function (name, params, absolute) {
    var self = {name: name, params: params, absolute: absolute};

    var routeshelper = {};
    
    routeshelper.current = (name) => {
        return route(undefined, undefined, undefined, Ziggy).current(name);
    }
    routeshelper.check = (name) => {
        return route(undefined, undefined, undefined, Ziggy).check(name);
    }
    routeshelper.url = () => {
        return route(self.name, undefined, undefined, Ziggy).url();
    }
    
    return route(name, params, absolute, Ziggy);
  }

If there are any improvements for the small helper please feel free to change it.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
bakerkretzmarcommented, Sep 25, 2020

I took a quick stab at a Hook that does something quite similar to your helper: useRoute (Ziggy Hook)

I could see this being something that might be worth including in Ziggy out of the box.

1reaction
lodzencommented, Sep 26, 2020

This looks great and i would appreciate it if this would be part of Ziggy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-mentions/README.md at master - GitHub
A React component that let's you mention people in a textarea like you are used to on Facebook or Twitter. Used in production...
Read more >
Writing an awesome Readme for your side projects
The design patterns implemented and code styles used. Status: Mention the status of the project. That is whether the project is completed or...
Read more >
react-basic-mentions - npm
React Basic Mentions is a first shot at a mention system : a user can mention someone in a comment (like Twitter or...
Read more >
How to Write a Good README File for Your GitHub Project
It can also be described as documentation with guidelines on how to use a project. Usually it will have instructions on how to...
Read more >
Source of README.md - react-demos - Magnolia Bitbucket
Create React App is divided into two packages: create-react-app is a global command-line utility that you use to create new projects. react- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found